mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 12:43:24 +00:00
Refactor usage message (#7803)
* Update usage string formation * Rework help message to use code generator interface * update * refactor
This commit is contained in:
@@ -78,88 +78,17 @@ int main(int argc, const char *argv[]) {
|
||||
g_program_name = argv[0];
|
||||
|
||||
const flatbuffers::FlatCompiler::Generator generators[] = {
|
||||
{ flatbuffers::GenerateBinary, "binary", false, nullptr,
|
||||
flatbuffers::IDLOptions::kBinary,
|
||||
flatbuffers::FlatCOption{
|
||||
"b", "binary", "",
|
||||
"Generate wire format binaries for any data definitions" },
|
||||
flatbuffers::BinaryMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateTextFile, "text", false, nullptr,
|
||||
flatbuffers::IDLOptions::kJson,
|
||||
flatbuffers::FlatCOption{
|
||||
"t", "json", "", "Generate text output for any data definitions" },
|
||||
|
||||
flatbuffers::TextMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateCPP, "C++", true, flatbuffers::GenerateCppGRPC,
|
||||
flatbuffers::IDLOptions::kCpp,
|
||||
flatbuffers::FlatCOption{ "c", "cpp", "",
|
||||
"Generate C++ headers for tables/structs" },
|
||||
flatbuffers::CPPMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateGo, "Go", true, flatbuffers::GenerateGoGRPC,
|
||||
flatbuffers::IDLOptions::kGo,
|
||||
flatbuffers::FlatCOption{ "g", "go", "",
|
||||
"Generate Go files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateJava, "Java", true, flatbuffers::GenerateJavaGRPC,
|
||||
flatbuffers::IDLOptions::kJava,
|
||||
flatbuffers::FlatCOption{ "j", "java", "",
|
||||
"Generate Java classes for tables/structs" },
|
||||
flatbuffers::JavaMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateDart, "Dart", true, nullptr,
|
||||
flatbuffers::IDLOptions::kDart,
|
||||
flatbuffers::FlatCOption{ "d", "dart", "",
|
||||
"Generate Dart classes for tables/structs" },
|
||||
flatbuffers::DartMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateTS, "TypeScript", true, flatbuffers::GenerateTSGRPC,
|
||||
flatbuffers::IDLOptions::kTs,
|
||||
flatbuffers::FlatCOption{ "T", "ts", "",
|
||||
"Generate TypeScript code for tables/structs" },
|
||||
flatbuffers::TSMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateCSharp, "C#", true, nullptr,
|
||||
flatbuffers::IDLOptions::kCSharp,
|
||||
flatbuffers::FlatCOption{ "n", "csharp", "",
|
||||
"Generate C# classes for tables/structs" },
|
||||
flatbuffers::CSharpMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GeneratePython, "Python", true,
|
||||
flatbuffers::GeneratePythonGRPC, flatbuffers::IDLOptions::kPython,
|
||||
flatbuffers::FlatCOption{ "p", "python", "",
|
||||
"Generate Python files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateLobster, "Lobster", true, nullptr,
|
||||
flatbuffers::IDLOptions::kLobster,
|
||||
flatbuffers::FlatCOption{ "", "lobster", "",
|
||||
"Generate Lobster files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateLua, "Lua", true, nullptr,
|
||||
flatbuffers::IDLOptions::kLua,
|
||||
flatbuffers::FlatCOption{ "l", "lua", "",
|
||||
"Generate Lua files for tables/structs" },
|
||||
nullptr, bfbs_gen_lua.get(), nullptr },
|
||||
{ flatbuffers::GenerateRust, "Rust", true, nullptr,
|
||||
flatbuffers::IDLOptions::kRust,
|
||||
flatbuffers::FlatCOption{ "r", "rust", "",
|
||||
"Generate Rust files for tables/structs" },
|
||||
flatbuffers::RustMakeRule, nullptr,
|
||||
flatbuffers::GenerateRustModuleRootFile },
|
||||
{ flatbuffers::GeneratePhp, "PHP", true, nullptr,
|
||||
flatbuffers::IDLOptions::kPhp,
|
||||
flatbuffers::FlatCOption{ "", "php", "",
|
||||
"Generate PHP files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateKotlin, "Kotlin", true, nullptr,
|
||||
flatbuffers::IDLOptions::kKotlin,
|
||||
flatbuffers::FlatCOption{ "", "kotlin", "",
|
||||
"Generate Kotlin classes for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateJsonSchema, "JsonSchema", true, nullptr,
|
||||
flatbuffers::IDLOptions::kJsonSchema,
|
||||
flatbuffers::FlatCOption{ "", "jsonschema", "", "Generate Json schema" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateSwift, "swift", true, flatbuffers::GenerateSwiftGRPC,
|
||||
flatbuffers::IDLOptions::kSwift,
|
||||
flatbuffers::FlatCOption{ "", "swift", "",
|
||||
"Generate Swift files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ nullptr, "Nim", true, nullptr, flatbuffers::IDLOptions::kNim,
|
||||
flatbuffers::FlatCOption{ "", "nim", "",
|
||||
"Generate Nim files for tables/structs" },
|
||||
@@ -174,84 +103,75 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
flatbuffers::FlatCompiler flatc(params);
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> binary_generator =
|
||||
flatbuffers::NewBinaryCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{
|
||||
"b", "binary", "",
|
||||
"Generate wire format binaries for any data definitions" },
|
||||
flatbuffers::NewBinaryCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> cpp_generator =
|
||||
flatbuffers::NewCppCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "c", "cpp", "",
|
||||
"Generate C++ headers for tables/structs" },
|
||||
flatbuffers::NewCppCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> csharp_generator =
|
||||
flatbuffers::NewCSharpCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "n", "csharp", "",
|
||||
"Generate C# classes for tables/structs" },
|
||||
flatbuffers::NewCSharpCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> dart_generator =
|
||||
flatbuffers::NewDartCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "d", "dart", "",
|
||||
"Generate Dart classes for tables/structs" },
|
||||
flatbuffers::NewDartCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> go_generator =
|
||||
flatbuffers::NewGoCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "g", "go", "",
|
||||
"Generate Go files for tables/structs" },
|
||||
flatbuffers::NewGoCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> java_generator =
|
||||
flatbuffers::NewJavaCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "j", "java", "",
|
||||
"Generate Java classes for tables/structs" },
|
||||
flatbuffers::NewJavaCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> json_schema_generator =
|
||||
flatbuffers::NewJsonSchemaCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "jsonschema", "", "Generate Json schema" },
|
||||
flatbuffers::NewJsonSchemaCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> kotlin_generator =
|
||||
flatbuffers::NewKotlinCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "kotlin", "",
|
||||
"Generate Kotlin classes for tables/structs" },
|
||||
flatbuffers::NewKotlinCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> lobster_generator =
|
||||
flatbuffers::NewLobsterCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "lobster", "",
|
||||
"Generate Lobster files for tables/structs" },
|
||||
flatbuffers::NewLobsterCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> php_generator =
|
||||
flatbuffers::NewPhpCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "php", "",
|
||||
"Generate PHP files for tables/structs" },
|
||||
flatbuffers::NewPhpCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> python_generator =
|
||||
flatbuffers::NewPythonCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "p", "python", "",
|
||||
"Generate Python files for tables/structs" },
|
||||
flatbuffers::NewPythonCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> rust_generator =
|
||||
flatbuffers::NewRustCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "r", "rust", "",
|
||||
"Generate Rust files for tables/structs" },
|
||||
flatbuffers::NewRustCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> swift_generator =
|
||||
flatbuffers::NewSwiftCodeGenerator();
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "swift", "",
|
||||
"Generate Swift files for tables/structs" },
|
||||
flatbuffers::NewSwiftCodeGenerator());
|
||||
|
||||
std::shared_ptr<flatbuffers::CodeGenerator> ts_generator =
|
||||
flatbuffers::NewTsCodeGenerator();
|
||||
|
||||
flatc.RegisterCodeGenerator("--binary", binary_generator);
|
||||
flatc.RegisterCodeGenerator("-b", binary_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--cpp", cpp_generator);
|
||||
flatc.RegisterCodeGenerator("-c", cpp_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--csharp", csharp_generator);
|
||||
flatc.RegisterCodeGenerator("-n", csharp_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--dart", dart_generator);
|
||||
flatc.RegisterCodeGenerator("-d", dart_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--go", go_generator);
|
||||
flatc.RegisterCodeGenerator("-g", go_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--java", java_generator);
|
||||
flatc.RegisterCodeGenerator("-j", java_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--jsonschema", json_schema_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--kotlin", kotlin_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--lobster", lobster_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--php", php_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--python", python_generator);
|
||||
flatc.RegisterCodeGenerator("-p", python_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--rust", rust_generator);
|
||||
flatc.RegisterCodeGenerator("-r", rust_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--swift", swift_generator);
|
||||
|
||||
flatc.RegisterCodeGenerator("--ts", ts_generator);
|
||||
flatc.RegisterCodeGenerator("-T", ts_generator);
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "T", "ts", "",
|
||||
"Generate TypeScript code for tables/structs" },
|
||||
flatbuffers::NewTsCodeGenerator());
|
||||
|
||||
// Create the FlatC options by parsing the command line arguments.
|
||||
const flatbuffers::FlatCOptions &options =
|
||||
|
||||
Reference in New Issue
Block a user