← 返回命令列表

Linux command

thrift 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Generate code

thrift --gen [language] [file.thrift]

Generate code

thrift --gen [language] -o [output_directory] [file.thrift]

Generate code

thrift --gen [language]:key1=val1,key2=val2 [file.thrift]

Generate code

thrift -r --gen [language] [file.thrift]

Add include search paths

thrift -I [include_dir] --gen [language] [file.thrift]

List all available generators

thrift --help

说明

thrift is the compiler for Apache Thrift, a framework for scalable cross-language services development. It combines a software stack with a code generation engine to build efficient and seamless services between languages like C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, JavaScript, Node.js, and more. The compiler reads a Thrift Interface Definition Language (IDL) file containing struct and service definitions, then generates language-specific implementation code. This enables developers to define data types and service interfaces once and generate the boilerplate code for multiple programming languages. Common generators include: cpp, java, py, rb, php, js, go, rs (Rust), swift, and many others. Run thrift without arguments to see all available generators for your installation.

参数

--gen _lang_:_key=val,..._
Generate code with the specified generator. Language options can be passed as comma-separated key=value pairs.
-o _dir_
Set the output directory for gen-* packages. Default is the current directory.
-out _dir_
Set the output location directly without creating a gen-* folder.
-I _dir_
Add a directory to search for include directives. Can be specified multiple times.
-r, --recurse
Also generate code for included Thrift files recursively.
-nowarn
Suppress all compiler warnings.
-strict
Enable strict compiler warnings.
-v, --verbose
Enable verbose output mode.
-debug
Print parse debug trace to stdout.
-version
Print the compiler version and exit.

FAQ

What is the thrift command used for?

thrift is the compiler for Apache Thrift, a framework for scalable cross-language services development. It combines a software stack with a code generation engine to build efficient and seamless services between languages like C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, JavaScript, Node.js, and more. The compiler reads a Thrift Interface Definition Language (IDL) file containing struct and service definitions, then generates language-specific implementation code. This enables developers to define data types and service interfaces once and generate the boilerplate code for multiple programming languages. Common generators include: cpp, java, py, rb, php, js, go, rs (Rust), swift, and many others. Run thrift without arguments to see all available generators for your installation.

How do I run a basic thrift example?

Run `thrift --gen [language] [file.thrift]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --gen _lang_:_key=val,..._ do in thrift?

Generate code with the specified generator. Language options can be passed as comma-separated key=value pairs.