diff --git a/docs/html/md__compiler.html b/docs/html/md__compiler.html index 2fe560da6..ff3f7fe22 100644 --- a/docs/html/md__compiler.html +++ b/docs/html/md__compiler.html @@ -61,18 +61,28 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
Using the schema compiler
-

Usage:

flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
+

Usage:

flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
       [ -- FILES...]
 

The files are read and parsed in order, and can contain either schemas or data (see below). Later files can make use of definitions in earlier files.

-- indicates that the following files are binary files in FlatBuffer format conforming to the schema(s) indicated before it. Incompatible binary files currently will give unpredictable results (!)

Depending on the flags passed, additional files may be generated for each file processed:

+

For any schema input files, one or more generators can be specified:

+
    +
  • --cpp, -c : Generate a C++ header for all definitions in this file (as filename_generated.h).
  • +
  • --java, -j : Generate Java code.
  • +
  • --csharp, -n : Generate C# code.
  • +
  • --go, -g : Generate Go code.
  • +
  • --python, -p: Generate Python code.
  • +
  • --javascript, -s: Generate JavaScript code.
  • +
  • --php: Generate PHP code.
  • +
+

For any data input files:

+
    +
  • --binary, -b : If data is contained in this file, generate a filename.bin containing the binary flatbuffer (or a different extension if one is specified in the schema).
  • +
  • --json, -t : If data is contained in this file, generate a filename.json representing the data in the flatbuffer.
  • +
+

Additional options:

    -
  • -c : Generate a C++ header for all definitions in this file (as filename_generated.h). Skipped for data.
  • -
  • -j : Generate Java classes. Skipped for data.
  • -
  • -n : Generate C# classes. Skipped for data.
  • -
  • -g : Generate Go classes. Skipped for data.
  • -
  • -b : If data is contained in this file, generate a filename.bin containing the binary flatbuffer.
  • -
  • -t : If data is contained in this file, generate a filename.json representing the data in the flatbuffer.
  • -o PATH : Output all generated files to PATH (either absolute, or relative to the current directory). If omitted, PATH will be the current directory. PATH should end in your systems path separator, e.g. / or \.
  • -I PATH : when encountering include statements, attempt to load the files from this path. Paths will be tried in the order given, and if all fail (or none are specified) it will try to load relative to the path of the schema file being parsed.
  • -M : Print make rules for generated files.
  • @@ -86,8 +96,9 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
  • --gen-onefile : Generate single output file (useful for C#)
  • --raw-binary : Allow binaries without a file_indentifier to be read. This may crash flatc given a mismatched schema.
  • --proto: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: package, message, enum, nested declarations, import (use -I for paths), extend, oneof, group. Does not support, but will skip without error: option, service, extensions, and most everything else.
  • -
  • --schema: Serialize schemas instead of JSON (use with -b). This will output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality.
  • +
  • --schema: Serialize schemas instead of JSON (use with -b). This will output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality.
+

NOTE: short-form options for generators are deprecated, use the long form whenever possible.

diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md index 4e6b7994b..27ddf52e4 100755 --- a/docs/source/Compiler.md +++ b/docs/source/Compiler.md @@ -2,7 +2,7 @@ Usage: - flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... + flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... [ -- FILES...] The files are read and parsed in order, and can contain either schemas @@ -16,21 +16,34 @@ Incompatible binary files currently will give unpredictable results (!) Depending on the flags passed, additional files may be generated for each file processed: -- `-c` : Generate a C++ header for all definitions in this file (as - `filename_generated.h`). Skipped for data. +For any schema input files, one or more generators can be specified: -- `-j` : Generate Java classes. Skipped for data. +- `--cpp`, `-c` : Generate a C++ header for all definitions in this file (as + `filename_generated.h`). -- `-n` : Generate C# classes. Skipped for data. +- `--java`, `-j` : Generate Java code. -- `-g` : Generate Go classes. Skipped for data. +- `--csharp`, `-n` : Generate C# code. -- `-b` : If data is contained in this file, generate a - `filename.bin` containing the binary flatbuffer. +- `--go`, `-g` : Generate Go code. -- `-t` : If data is contained in this file, generate a +- `--python`, `-p`: Generate Python code. + +- `--javascript`, `-s`: Generate JavaScript code. + +- `--php`: Generate PHP code. + +For any data input files: + +- `--binary`, `-b` : If data is contained in this file, generate a + `filename.bin` containing the binary flatbuffer (or a different extension + if one is specified in the schema). + +- `--json`, `-t` : If data is contained in this file, generate a `filename.json` representing the data in the flatbuffer. +Additional options: + - `-o PATH` : Output all generated files to PATH (either absolute, or relative to the current directory). If omitted, PATH will be the current directory. PATH should end in your systems path separator, @@ -82,3 +95,6 @@ be generated for each file processed: output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality. + +NOTE: short-form options for generators are deprecated, use the long form +whenever possible. diff --git a/src/flatc.cpp b/src/flatc.cpp index 337ce5d8e..2479da12b 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -28,7 +28,8 @@ struct Generator { const std::string &path, const std::string &file_name, const flatbuffers::GeneratorOptions &opts); - const char *generator_opt; + const char *generator_opt_short; + const char *generator_opt_long; const char *lang_name; flatbuffers::GeneratorOptions::Language lang; const char *generator_help; @@ -40,41 +41,41 @@ struct Generator { }; const Generator generators[] = { - { flatbuffers::GenerateBinary, "-b", "binary", + { flatbuffers::GenerateBinary, "-b", "--binary", "binary", flatbuffers::GeneratorOptions::kMAX, "Generate wire format binaries for any data definitions", flatbuffers::BinaryMakeRule }, - { flatbuffers::GenerateTextFile, "-t", "text", + { flatbuffers::GenerateTextFile, "-t", "--json", "text", flatbuffers::GeneratorOptions::kMAX, "Generate text output for any data definitions", flatbuffers::TextMakeRule }, - { flatbuffers::GenerateCPP, "-c", "C++", + { flatbuffers::GenerateCPP, "-c", "--cpp", "C++", flatbuffers::GeneratorOptions::kMAX, "Generate C++ headers for tables/structs", flatbuffers::CPPMakeRule }, - { flatbuffers::GenerateGo, "-g", "Go", + { flatbuffers::GenerateGo, "-g", "--go", "Go", flatbuffers::GeneratorOptions::kGo, "Generate Go files for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GenerateGeneral, "-j", "Java", + { flatbuffers::GenerateGeneral, "-j", "--java", "Java", flatbuffers::GeneratorOptions::kJava, "Generate Java classes for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GenerateJS, "-s", "JavaScript", + { flatbuffers::GenerateJS, "-s", "--js", "JavaScript", flatbuffers::GeneratorOptions::kMAX, "Generate JavaScript code for tables/structs", flatbuffers::JSMakeRule }, - { flatbuffers::GenerateGeneral, "-n", "C#", + { flatbuffers::GenerateGeneral, "-n", "--csharp", "C#", flatbuffers::GeneratorOptions::kCSharp, "Generate C# classes for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GeneratePython, "-p", "Python", + { flatbuffers::GeneratePython, "-p", "--python", "Python", flatbuffers::GeneratorOptions::kMAX, "Generate Python files for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GeneratePhp, "--php", "PHP", + { flatbuffers::GeneratePhp, nullptr, "--php", "PHP", flatbuffers::GeneratorOptions::kMAX, - "Generate Php files for tables/structs", + "Generate PHP files for tables/structs", flatbuffers::GeneralMakeRule }, }; @@ -86,8 +87,11 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) { if (usage) { printf("usage: %s [OPTION]... FILE... [-- FILE...]\n", program_name); for (size_t i = 0; i < sizeof(generators) / sizeof(generators[0]); ++i) - printf(" %s %s.\n", - generators[i].generator_opt, + printf(" %-12s %s %s.\n", + generators[i].generator_opt_long, + generators[i].generator_opt_short + ? generators[i].generator_opt_short + : " ", generators[i].generator_help); printf( " -o PATH Prefix PATH to all generated files.\n" @@ -179,7 +183,9 @@ int main(int argc, const char *argv[]) { print_make_rules = true; } else { for (size_t i = 0; i < num_generators; ++i) { - if (arg == generators[i].generator_opt) { + if (arg == generators[i].generator_opt_long || + (generators[i].generator_opt_short && + arg == generators[i].generator_opt_short)) { generator_enabled[i] = true; any_generator = true; goto found; diff --git a/tests/generate_code.sh b/tests/generate_code.sh index 91158bff4..91661f30d 100644 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -1,2 +1,2 @@ -../flatc -c -j -n -g -b -p -s --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json -../flatc -b --schema monster_test.fbs +../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json +../flatc --binary --schema monster_test.fbs diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 8d54ead7e..e5f51face 100644 Binary files a/tests/monster_test.bfbs and b/tests/monster_test.bfbs differ diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index d46a9c684..9d0f48b09 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -352,6 +352,8 @@ MyGame.Example.Stat.endStat = function(builder) { }; /** + * an example documentation comment: monster object + * * @constructor */ MyGame.Example.Monster = function() {