From 3cbc120a08edf6db9ab8f5c2c44f8a40be70d6bc Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Mon, 13 Dec 2021 13:56:47 -0800 Subject: [PATCH] Refractor Flatc Options (#6987) * Moved error/warnings to bottom of std error * Refactor flatc options * pass program name to flatc * extra -- in one option * merge of upstream --- include/flatbuffers/flatc.h | 11 +- src/flatc.cpp | 362 +++++++++++++++++++++++------------- src/flatc_main.cpp | 132 +++++++------ 3 files changed, 317 insertions(+), 188 deletions(-) diff --git a/include/flatbuffers/flatc.h b/include/flatbuffers/flatc.h index c6a651bee..a9eacf019 100644 --- a/include/flatbuffers/flatc.h +++ b/include/flatbuffers/flatc.h @@ -31,6 +31,13 @@ namespace flatbuffers { extern void LogCompilerWarn(const std::string &warn); extern void LogCompilerError(const std::string &err); +struct FlatCOption { + std::string short_opt; + std::string long_opt; + std::string parameter; + std::string description; +}; + class FlatCompiler { public: // Output generator for the various programming languages and formats we @@ -44,13 +51,11 @@ class FlatCompiler { const std::string &file_name); GenerateFn generate; - const char *generator_opt_short; - const char *generator_opt_long; const char *lang_name; bool schema_only; GenerateFn generateGRPC; flatbuffers::IDLOptions::Language lang; - const char *generator_help; + FlatCOption option; MakeRuleFn make_rule; BfbsGenerator *bfbs_generator; }; diff --git a/src/flatc.cpp b/src/flatc.cpp index 6b9fdc01a..91220b483 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -17,6 +17,7 @@ #include "flatbuffers/flatc.h" #include +#include #include "bfbs_gen_lua.h" #include "flatbuffers/util.h" @@ -59,141 +60,234 @@ void FlatCompiler::Error(const std::string &err, bool usage, params_.error_fn(this, err, usage, show_exe_name); } +const static FlatCOption options[] = { + { "o", "", "PATH", "Prefix PATH to all generated files." }, + { "I", "", "PATH", "Search for includes in the specified path." }, + { "M", "", "", "Print make rules for generated files." }, + { "", "version", "", "Print the version number of flatc and exit." }, + { "", "help", "", "Prints this help text and exit." }, + { "", "string-json", "", + "Strict JSON: field names must be / will be quoted, no trailing commas in " + "tables/vectors." }, + { "", "allow-non-utf8", "", + "Pass non-UTF-8 input through parser and emit nonstandard \\x escapes in " + "JSON. (Default is to raise parse error on non-UTF-8 input.)" }, + { "", "natural-utf8", "", + "Output strings with UTF-8 as human-readable strings. By default, UTF-8 " + "characters are printed as \\uXXXX escapes." }, + { "", "defaults-json", "", + "Output fields whose value is the default when writing JSON" }, + { "", "unknown-json", "", + "Allow fields in JSON that are not defined in the schema. These fields " + "will be discared when generating binaries." }, + { "", "no-prefix", "", + "Don\'t prefix enum values with the enum type in C++." }, + { "", "scoped-enums", "", + "Use C++11 style scoped and strongly typed enums. Also implies " + "--no-prefix." }, + { "", "gen-inclues", "", + "(deprecated), this is the default behavior. If the original behavior is " + "required (no include statements) use --no-includes." }, + { "", "no-includes", "", + "Don\'t generate include statements for included schemas the generated " + "file depends on (C++ / Python)." }, + { "", "gen-mutable", "", + "Generate accessors that can mutate buffers in-place." }, + { "", "gen-onefile", "", + "Generate single output file for C#, Go, and Python." }, + { "", "gen-name-strings", "", + "Generate type name functions for C++ and Rust." }, + { "", "gen-object-api", "", "Generate an additional object-based API." }, + { "", "gen-compare", "", "Generate operator== for object-based API types." }, + { "", "gen-nullable", "", + "Add Clang _Nullable for C++ pointer. or @Nullable for Java" }, + { "", "java-checkerframe", "", "Add @Pure for Java." }, + { "", "gen-generated", "", "Add @Generated annotation for Java." }, + { "", "gen-jvmstatic", "", + "Add @JvmStatic annotation for Kotlin methods in companion object for " + "interop from Java to Kotlin." }, + { "", "gen-all", "", + "Generate not just code for the current schema files, but for all files it " + "includes as well. If the language uses a single file for output (by " + "default the case for C++ and JS), all code will end up in this one " + "file." }, + { "", "gen-json-emit", "", + "Generates encoding code which emits Flatbuffers into JSON" }, + { "", "cpp-include", "", "Adds an #include in generated file." }, + { "", "cpp-ptr-type", "T", + "Set object API pointer type (default std::unique_ptr)." }, + { "", "cpp-str-type", "T", + "Set object API string type (default std::string). T::c_str(), T::length() " + "and T::empty() must be supported. The custom type also needs to be " + "constructible from std::string (see the --cpp-str-flex-ctor option to " + "change this behavior)" }, + { "", "cpp-str-flex-ctor", "", + "Don't construct custom string types by passing std::string from " + "Flatbuffers, but (char* + length)." }, + { "", "cpp-field-case-style", "STYLE", + "Generate C++ fields using selected case style. Supported STYLE values: * " + "'unchanged' - leave unchanged (default) * 'upper' - schema snake_case " + "emits UpperCamel; * 'lower' - schema snake_case emits lowerCamel." }, + { "", "cpp-std", "CPP_STD", + "Generate a C++ code using features of selected C++ standard. Supported " + "CPP_STD values: * 'c++0x' - generate code compatible with old compilers; " + "'c++11' - use C++11 code generator (default); * 'c++17' - use C++17 " + "features in generated code (experimental)." }, + { "", "cpp-static-reflection", "", + "When using C++17, generate extra code to provide compile-time (static) " + "reflection of Flatbuffers types. Requires --cpp-std to be \"c++17\" or " + "higher." }, + { "", "object-prefix", "PREFIX", + "Customize class prefix for C++ object-based API." }, + { "", "object-suffix", "SUFFIX", + "Customize class suffix for C++ object-based API. Default Value is " + "\"T\"." }, + { "", "go-namespace", "", "Generate the overriding namespace in Golang." }, + { "", "go-import", "IMPORT", + "Generate the overriding import for flatbuffers in Golang (default is " + "\"github.com/google/flatbuffers/go\")." }, + { "", "raw-binary", "", + "Allow binaries without file_identifier to be read. This may crash flatc " + "given a mismatched schema." }, + { "", "size-prefixed", "", "Input binaries are size prefixed buffers." }, + { "", "proto", "", "Input is a .proto, translate to .fbs." }, + { "", "proto-namespace-suffix", "SUFFIX", + "Add this namespace to any flatbuffers generated from protobufs." }, + { "", "oneof-union", "", "Translate .proto oneofs to flatbuffer unions." }, + { "", "grpc", "", "Generate GRPC interfaces for the specified languages." }, + { "", "schema", "", "Serialize schemas instead of JSON (use with -b)." }, + { "", "bfbs-filenames", "PATH", + "Sets the root path where reflection filenames in reflection.fbs are " + "relative to. The 'root' is denoted with `//`. E.g. if PATH=/a/b/c " + "then /a/d/e.fbs will be serialized as //../d/e.fbs. (PATH defaults to the " + "directory of the first provided schema file." }, + { "", "bfbs-comments", "", "Add doc comments to the binary schema files." }, + { "", "bfbs-builtins", "", + "Add builtin attributes to the binary schema files." }, + { "", "bfbs-gen-embed", "", + "Generate code to embed the bfbs schema to the source." }, + { "", "conform", "FILE", + "Specify a schema the following schemas should be an evolution of. Gives " + "errors if not." }, + { "", "conform-includes", "PATH", + "Include path for the schema given with --conform PATH" }, + { "", "filename-suffix", "SUFFIX", + "The suffix appended to the generated file names (Default is " + "'_generated')." }, + { "", "filename-ext", "EXT", + "The extension appended to the generated file names. Default is " + "language-specific (e.g., '.h' for C++)" }, + { "", "include-prefix", "PATH", + "Prefix this PATH to any generated include statements." }, + { "", "keep-prefix", "", + "Keep original prefix of schema include statement." }, + { "", "reflect-types", "", + "Add minimal type reflection to code generation." }, + { "", "reflect-names", "", "Add minimal type/name reflection." }, + { "", "root-type", "T", "Select or override the default root_type." }, + { "", "require-explicit-ids", "", + "When parsing schemas, require explicit ids (id: x)." }, + { "", "force-defaults", "", + "Emit default values in binary output from JSON" }, + { "", "force-empty", "", + "When serializing from object API representation, force strings and " + "vectors to empty rather than null." }, + { "", "force-empty-vectors", "", + "When serializing from object API representation, force vectors to empty " + "rather than null." }, + { "", "flexbuffers", "", + "Used with \"binary\" and \"json\" options, it generates data using " + "schema-less FlexBuffers." }, + { "", "no-warnings", "", "Inhibit all warnings messages." }, + { "", "cs-global-alias", "", + "Prepend \"global::\" to all user generated csharp classes and " + "structs." }, + { "", "cs-gen-json-serializer", "", + "Allows (de)serialization of JSON text in the Object API. (requires " + "--gen-object-api)." }, +}; + +static void AppendTextWrappedString(std::stringstream &ss, std::string &text, + size_t max_col, size_t start_col) { + size_t max_line_length = max_col - start_col; + + if (text.length() > max_line_length) { + size_t ideal_break_location = text.rfind(' ', max_line_length); + size_t length = std::min(max_line_length, ideal_break_location); + ss << text.substr(0, length) << "\n"; + ss << std::string(start_col, ' '); + std::string rest_of_description = text.substr( + ((ideal_break_location < max_line_length || text.at(length) == ' ') + ? length + 1 + : length)); + AppendTextWrappedString(ss, rest_of_description, max_col, start_col); + } else { + ss << text; + } +} + +static void AppendOption(std::stringstream &ss, const FlatCOption &option, + size_t max_col, size_t min_col_for_description) { + size_t chars = 2; + ss << " "; + if (!option.short_opt.empty()) { + chars += 2 + option.short_opt.length(); + ss << "-" << option.short_opt; + if (!option.long_opt.empty()) { + chars++; + ss << ","; + } + ss << " "; + } + if (!option.long_opt.empty()) { + chars += 3 + option.long_opt.length(); + ss << "--" << option.long_opt << " "; + } + if (!option.parameter.empty()) { + chars += 1 + option.parameter.length(); + ss << option.parameter << " "; + } + size_t start_of_description = chars; + if (start_of_description > min_col_for_description) { + ss << "\n"; + start_of_description = min_col_for_description; + ss << std::string(start_of_description, ' '); + } else { + while (start_of_description < min_col_for_description) { + ss << " "; + start_of_description++; + } + } + if (!option.description.empty()) { + std::string description = option.description; + AppendTextWrappedString(ss, description, max_col, start_of_description); + } + ss << "\n"; +} + std::string FlatCompiler::GetUsageString(const char *program_name) const { std::stringstream ss; ss << "Usage: " << program_name << " [OPTION]... FILE... [-- FILE...]\n"; for (size_t i = 0; i < params_.num_generators; ++i) { const Generator &g = params_.generators[i]; - - std::stringstream full_name; - full_name << std::setw(16) << std::left << g.generator_opt_long; - const char *name = g.generator_opt_short ? g.generator_opt_short : " "; - const char *help = g.generator_help; - - ss << " " << full_name.str() << " " << name << " " << help << ".\n"; + AppendOption(ss, g.option, 80, 25); } - // clang-format off - // Output width - // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 - ss << - " -o PATH Prefix PATH to all generated files.\n" - " -I PATH Search for includes in the specified path.\n" - " -M Print make rules for generated files.\n" - " --version Print the version number of flatc and exit.\n" - " --strict-json Strict JSON: field names must be / will be quoted,\n" - " no trailing commas in tables/vectors.\n" - " --allow-non-utf8 Pass non-UTF-8 input through parser and emit nonstandard\n" - " \\x escapes in JSON. (Default is to raise parse error on\n" - " non-UTF-8 input.)\n" - " --natural-utf8 Output strings with UTF-8 as human-readable strings.\n" - " By default, UTF-8 characters are printed as \\uXXXX escapes.\n" - " --defaults-json Output fields whose value is the default when\n" - " writing JSON\n" - " --unknown-json Allow fields in JSON that are not defined in the\n" - " schema. These fields will be discared when generating\n" - " binaries.\n" - " --no-prefix Don\'t prefix enum values with the enum type in C++.\n" - " --scoped-enums Use C++11 style scoped and strongly typed enums.\n" - " also implies --no-prefix.\n" - " --gen-includes (deprecated), this is the default behavior.\n" - " If the original behavior is required (no include\n" - " statements) use --no-includes.\n" - " --no-includes Don\'t generate include statements for included\n" - " schemas the generated file depends on (C++ / Python).\n" - " --gen-mutable Generate accessors that can mutate buffers in-place.\n" - " --gen-onefile Generate single output file for C#, Go, and Python.\n" - " --gen-name-strings Generate type name functions for C++ and Rust.\n" - " --gen-object-api Generate an additional object-based API.\n" - " --gen-compare Generate operator== for object-based API types.\n" - " --gen-nullable Add Clang _Nullable for C++ pointer. or @Nullable for Java\n" - " --java-checkerframe work Add @Pure for Java.\n" - " --gen-generated Add @Generated annotation for Java\n" - " --gen-jvmstatic Add @JvmStatic annotation for Kotlin methods\n" - " in companion object for interop from Java to Kotlin.\n" - " --gen-all Generate not just code for the current schema files,\n" - " but for all files it includes as well.\n" - " If the language uses a single file for output (by default\n" - " the case for C++ and JS), all code will end up in this one\n" - " file.\n" - " --gen-json-emit Generates encoding code which emits Flatbuffers into JSON\n" - " --cpp-include Adds an #include in generated file.\n" - " --cpp-ptr-type T Set object API pointer type (default std::unique_ptr).\n" - " --cpp-str-type T Set object API string type (default std::string).\n" - " T::c_str(), T::length() and T::empty() must be supported.\n" - " The custom type also needs to be constructible from std::string\n" - " (see the --cpp-str-flex-ctor option to change this behavior).\n" - " --cpp-str-flex-ctor Don't construct custom string types by passing std::string\n" - " from Flatbuffers, but (char* + length).\n" - " --cpp-field-case-style STYLE Generate C++ fields using selected case style.\n" - " Supported STYLE values:\n" - " * 'unchanged' - leave unchanged (default);\n" - " * 'upper' - schema snake_case emits UpperCamel;\n" - " * 'lower' - schema snake_case emits lowerCamel.\n" - " --cpp-std CPP_STD Generate a C++ code using features of selected C++ standard.\n" - " Supported CPP_STD values:\n" - " * 'c++0x' - generate code compatible with old compilers;\n" - " * 'c++11' - use C++11 code generator (default);\n" - " * 'c++17' - use C++17 features in generated code (experimental).\n" - " --cpp-static-reflection When using C++17, generate extra code to provide compile-time\n" - " (static) reflection of Flatbuffers types. Requires --cpp-std\n" - " to be \"c++17\" or higher.\n" - " --object-prefix Customise class prefix for C++ object-based API.\n" - " --object-suffix Customise class suffix for C++ object-based API.\n" - " Default value is \"T\".\n" - " --go-namespace Generate the overriding namespace in Golang.\n" - " --go-import Generate the overriding import for flatbuffers in Golang\n" - " (default is \"github.com/google/flatbuffers/go\").\n" - " --raw-binary Allow binaries without file_identifier to be read.\n" - " This may crash flatc given a mismatched schema.\n" - " --size-prefixed Input binaries are size prefixed buffers.\n" - " --proto Input is a .proto, translate to .fbs.\n" - " --proto-namespace-suffix Add this namespace to any flatbuffers generated\n" - " SUFFIX from protobufs.\n" - " --oneof-union Translate .proto oneofs to flatbuffer unions.\n" - " --grpc Generate GRPC interfaces for the specified languages.\n" - " --schema Serialize schemas instead of JSON (use with -b).\n" - " --bfbs-filenames PATH Sets the root path where reflection filenames in \n" - " reflection.fbs are relative to. The 'root' is denoted with \n" - " `//`. E.g. if PATH=/a/b/c \n then /a/d/e.fbs will be serialized\n" - " as //../d/e.fbs. (PATH defaults to the directory of the first\n" - " provided schema file.)\n" - " --bfbs-comments Add doc comments to the binary schema files.\n" - " --bfbs-builtins Add builtin attributes to the binary schema files.\n" - " --bfbs-gen-embed Generate code to embed the bfbs schema to the source.\n" - " --conform FILE Specify a schema the following schemas should be\n" - " an evolution of. Gives errors if not.\n" - " --conform-includes Include path for the schema given with --conform PATH\n" - " --filename-suffix The suffix appended to the generated file names.\n" - " Default is '_generated'.\n" - " --filename-ext The extension appended to the generated file names.\n" - " Default is language-specific (e.g., '.h' for C++)\n" - " --include-prefix Prefix this path to any generated include statements.\n" - " PATH\n" - " --keep-prefix Keep original prefix of schema include statement.\n" - " --reflect-types Add minimal type reflection to code generation.\n" - " --reflect-names Add minimal type/name reflection.\n" - " --root-type T Select or override the default root_type\n" - " --require-explicit-ids When parsing schemas, require explicit ids (id: x).\n" - " --force-defaults Emit default values in binary output from JSON\n" - " --force-empty When serializing from object API representation,\n" - " force strings and vectors to empty rather than null.\n" - " --force-empty-vectors When serializing from object API representation,\n" - " force vectors to empty rather than null.\n" - " --flexbuffers Used with \"binary\" and \"json\" options, it generates\n" - " data using schema-less FlexBuffers.\n" - " --no-warnings Inhibit all warning messages.\n" - " --cs-global-alias Prepend \"global::\" to all user generated csharp classes and structs.\n" - " --cs-gen-json-serializer Allows (de)serialization of JSON text in the Object\n" - " API. (requires --gen-object-api).\n" - "FILEs may be schemas (must end in .fbs), binary schemas (must end in .bfbs),\n" - "or JSON files (conforming to preceding schema). FILEs after the -- must be\n" - "binary flatbuffer format files.\n" - "Output files are named using the base file name of the input,\n" - "and written to the current directory or the path given by -o.\n" - "example: " << program_name << " -c -b schema1.fbs schema2.fbs data.json\n"; - // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 - // clang-format on + ss << "\n"; + for (const FlatCOption &option : options) { + AppendOption(ss, option, 80, 25); + } + ss << "\n"; + + std::string files_description = + "FILEs may be schemas (must end in .fbs), binary schemas (must end in " + ".bfbs) or JSON files (conforming to preceding schema). FILEs after the " + "-- must be binary flatbuffer format files. Output files are named using " + "the base file name of the input, and written to the current directory " + "or the path given by -o. example: " + + std::string(program_name) + " -c -b schema1.fbs schema2.fbs data.json"; + AppendTextWrappedString(ss, files_description, 80, 0); + ss << "\n"; return ss.str(); } @@ -219,7 +313,9 @@ int FlatCompiler::Compile(int argc, const char **argv) { size_t binary_files_from = std::numeric_limits::max(); std::string conform_to_schema; - for (int argi = 0; argi < argc; argi++) { + const char *program_name = argv[0]; + + for (int argi = 1; argi < argc; argi++) { std::string arg = argv[argi]; if (arg[0] == '-') { if (filenames.size() && arg[1] != '-') @@ -354,6 +450,9 @@ int FlatCompiler::Compile(int argc, const char **argv) { } else if (arg == "--version") { printf("flatc version %s\n", FLATC_VERSION()); exit(0); + } else if (arg == "--help") { + printf("%s\n", GetUsageString(program_name).c_str()); + exit(0); } else if (arg == "--grpc") { grpc_enabled = true; } else if (arg == "--bfbs-comments") { @@ -406,9 +505,8 @@ int FlatCompiler::Compile(int argc, const char **argv) { opts.cs_global_alias = true; } else { for (size_t i = 0; i < params_.num_generators; ++i) { - if (arg == params_.generators[i].generator_opt_long || - (params_.generators[i].generator_opt_short && - arg == params_.generators[i].generator_opt_short)) { + if (arg == "--" + params_.generators[i].option.long_opt || + arg == "-" + params_.generators[i].option.short_opt) { generator_enabled[i] = true; any_generator = true; opts.lang_to_generate |= params_.generators[i].lang; diff --git a/src/flatc_main.cpp b/src/flatc_main.cpp index bdf23d082..e8a51a589 100644 --- a/src/flatc_main.cpp +++ b/src/flatc_main.cpp @@ -27,16 +27,16 @@ static void Warn(const flatbuffers::FlatCompiler *flatc, const std::string &warn, bool show_exe_name) { (void)flatc; if (show_exe_name) { printf("%s: ", g_program_name); } - fprintf(stderr, "warning: %s\n", warn.c_str()); + fprintf(stderr, "warning:\n %s\n\n", warn.c_str()); } static void Error(const flatbuffers::FlatCompiler *flatc, const std::string &err, bool usage, bool show_exe_name) { if (show_exe_name) { printf("%s: ", g_program_name); } - fprintf(stderr, "error: %s\n", err.c_str()); if (usage && flatc) { - fprintf(stderr, "%s", flatc->GetUsageString(g_program_name).c_str()); + fprintf(stderr, "%s\n", flatc->GetUsageString(g_program_name).c_str()); } + fprintf(stderr, "error:\n %s\n\n", err.c_str()); exit(1); } @@ -62,61 +62,87 @@ int main(int argc, const char *argv[]) { g_program_name = argv[0]; const flatbuffers::FlatCompiler::Generator generators[] = { - { flatbuffers::GenerateBinary, "-b", "--binary", "binary", false, nullptr, + { flatbuffers::GenerateBinary, "binary", false, nullptr, flatbuffers::IDLOptions::kBinary, - "Generate wire format binaries for any data definitions", + flatbuffers::FlatCOption{ + "b", "binary", "", + "Generate wire format binaries for any data definitions" }, flatbuffers::BinaryMakeRule, nullptr }, - { flatbuffers::GenerateTextFile, "-t", "--json", "text", false, nullptr, + { flatbuffers::GenerateTextFile, "text", false, nullptr, flatbuffers::IDLOptions::kJson, - "Generate text output for any data definitions", + flatbuffers::FlatCOption{ + "t", "json", "", "Generate text output for any data definitions" }, + flatbuffers::TextMakeRule, nullptr }, - { flatbuffers::GenerateCPP, "-c", "--cpp", "C++", true, - flatbuffers::GenerateCppGRPC, flatbuffers::IDLOptions::kCpp, - "Generate C++ headers for tables/structs", flatbuffers::CPPMakeRule, - nullptr }, - { flatbuffers::GenerateGo, "-g", "--go", "Go", true, - flatbuffers::GenerateGoGRPC, flatbuffers::IDLOptions::kGo, - "Generate Go files for tables/structs", nullptr, nullptr }, - { flatbuffers::GenerateJava, "-j", "--java", "Java", true, - flatbuffers::GenerateJavaGRPC, flatbuffers::IDLOptions::kJava, - "Generate Java classes for tables/structs", flatbuffers::JavaMakeRule, - nullptr }, - { flatbuffers::GenerateDart, "-d", "--dart", "Dart", true, nullptr, - flatbuffers::IDLOptions::kDart, - "Generate Dart classes for tables/structs", flatbuffers::DartMakeRule, - nullptr }, - { flatbuffers::GenerateTS, "-T", "--ts", "TypeScript", true, - flatbuffers::GenerateTSGRPC, flatbuffers::IDLOptions::kTs, - "Generate TypeScript code for tables/structs", flatbuffers::TSMakeRule, - nullptr }, - { flatbuffers::GenerateCSharp, "-n", "--csharp", "C#", true, nullptr, - flatbuffers::IDLOptions::kCSharp, - "Generate C# classes for tables/structs", flatbuffers::CSharpMakeRule, - nullptr }, - { flatbuffers::GeneratePython, "-p", "--python", "Python", true, - flatbuffers::GeneratePythonGRPC, flatbuffers::IDLOptions::kPython, - "Generate Python files for tables/structs", nullptr, nullptr }, - { flatbuffers::GenerateLobster, nullptr, "--lobster", "Lobster", true, - nullptr, flatbuffers::IDLOptions::kLobster, - "Generate Lobster files for tables/structs", nullptr, nullptr }, - { flatbuffers::GenerateLua, "-l", "--lua", "Lua", true, nullptr, - flatbuffers::IDLOptions::kLua, "Generate Lua files for tables/structs", - nullptr, bfbs_gen_lua.get() }, - { flatbuffers::GenerateRust, "-r", "--rust", "Rust", true, nullptr, - flatbuffers::IDLOptions::kRust, "Generate Rust files for tables/structs", - flatbuffers::RustMakeRule, nullptr }, - { flatbuffers::GeneratePhp, nullptr, "--php", "PHP", true, nullptr, - flatbuffers::IDLOptions::kPhp, "Generate PHP files for tables/structs", + { flatbuffers::GenerateCPP, "C++", true, flatbuffers::GenerateCppGRPC, + flatbuffers::IDLOptions::kCpp, + flatbuffers::FlatCOption{ "c", "cpp", "", + "Generate C++ headers for tables/structs" }, + flatbuffers::CPPMakeRule, nullptr }, + { flatbuffers::GenerateGo, "Go", true, flatbuffers::GenerateGoGRPC, + flatbuffers::IDLOptions::kGo, + flatbuffers::FlatCOption{ "g", "go", "", + "Generate Go files for tables/structs" }, nullptr, nullptr }, - { flatbuffers::GenerateKotlin, nullptr, "--kotlin", "Kotlin", true, nullptr, + { flatbuffers::GenerateJava, "Java", true, flatbuffers::GenerateJavaGRPC, + flatbuffers::IDLOptions::kJava, + flatbuffers::FlatCOption{ "j", "java", "", + "Generate Java classes for tables/structs" }, + flatbuffers::JavaMakeRule, nullptr }, + { flatbuffers::GenerateDart, "Dart", true, nullptr, + flatbuffers::IDLOptions::kDart, + flatbuffers::FlatCOption{ "d", "dart", "", + "Generate Dart classes for tables/structs" }, + flatbuffers::DartMakeRule, nullptr }, + { flatbuffers::GenerateTS, "TypeScript", true, flatbuffers::GenerateTSGRPC, + flatbuffers::IDLOptions::kTs, + flatbuffers::FlatCOption{ "T", "ts", "", + "Generate TypeScript code for tables/structs" }, + flatbuffers::TSMakeRule, nullptr }, + { flatbuffers::GenerateCSharp, "C#", true, nullptr, + flatbuffers::IDLOptions::kCSharp, + flatbuffers::FlatCOption{ "n", "csharp", "", + "Generate C# classes for tables/structs" }, + flatbuffers::CSharpMakeRule, nullptr }, + { flatbuffers::GeneratePython, "Python", true, + flatbuffers::GeneratePythonGRPC, flatbuffers::IDLOptions::kPython, + flatbuffers::FlatCOption{ "p", "python", "", + "Generate Python files for tables/structs" }, + nullptr, nullptr }, + { flatbuffers::GenerateLobster, "Lobster", true, nullptr, + flatbuffers::IDLOptions::kLobster, + flatbuffers::FlatCOption{ "", "lobster", "", + "Generate Lobster files for tables/structs" }, + 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() }, + { flatbuffers::GenerateRust, "Rust", true, nullptr, + flatbuffers::IDLOptions::kRust, + flatbuffers::FlatCOption{ "r", "rust", "", + "Generate Rust files for tables/structs" }, + flatbuffers::RustMakeRule, nullptr }, + { flatbuffers::GeneratePhp, "PHP", true, nullptr, + flatbuffers::IDLOptions::kPhp, + flatbuffers::FlatCOption{ "", "php", "", + "Generate PHP files for tables/structs" }, + nullptr, nullptr }, + { flatbuffers::GenerateKotlin, "Kotlin", true, nullptr, flatbuffers::IDLOptions::kKotlin, - "Generate Kotlin classes for tables/structs", nullptr, nullptr }, - { flatbuffers::GenerateJsonSchema, nullptr, "--jsonschema", "JsonSchema", - true, nullptr, flatbuffers::IDLOptions::kJsonSchema, - "Generate Json schema", nullptr, nullptr }, - { flatbuffers::GenerateSwift, nullptr, "--swift", "swift", true, - flatbuffers::GenerateSwiftGRPC, flatbuffers::IDLOptions::kSwift, - "Generate Swift files for tables/structs", nullptr, nullptr }, + flatbuffers::FlatCOption{ "", "kotlin", "", + "Generate Kotlin classes for tables/structs" }, + nullptr, nullptr }, + { flatbuffers::GenerateJsonSchema, "JsonSchema", true, nullptr, + flatbuffers::IDLOptions::kJsonSchema, + flatbuffers::FlatCOption{ "", "jsonschema", "", "Generate Json schema" }, + nullptr, nullptr }, + { flatbuffers::GenerateSwift, "swift", true, flatbuffers::GenerateSwiftGRPC, + flatbuffers::IDLOptions::kSwift, + flatbuffers::FlatCOption{ "", "swift", "", + "Generate Swift files for tables/structs" }, + nullptr, nullptr }, }; flatbuffers::FlatCompiler::InitParams params; @@ -126,5 +152,5 @@ int main(int argc, const char *argv[]) { params.error_fn = Error; flatbuffers::FlatCompiler flatc(params); - return flatc.Compile(argc - 1, argv + 1); + return flatc.Compile(argc, argv); }