Added long form options for all generators (--cpp etc.)

Short-form versions are still supported, but are deprecated.

Change-Id: I15f70ca8d69ba5790368205caa9603b65e1b7fff
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen 2015-11-25 17:26:34 -08:00
parent b7d8c2af1a
commit d7b4a31e93
6 changed files with 68 additions and 33 deletions

View File

@ -61,18 +61,28 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
<div class="title">Using the schema compiler </div> </div> <div class="title">Using the schema compiler </div> </div>
</div><!--header--> </div><!--header-->
<div class="contents"> <div class="contents">
<div class="textblock"><p>Usage: </p><pre class="fragment">flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... <div class="textblock"><p>Usage: </p><pre class="fragment">flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
[ -- FILES...] [ -- FILES...]
</pre><p>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.</p> </pre><p>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.</p>
<p><code>--</code> 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 (!)</p> <p><code>--</code> 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 (!)</p>
<p>Depending on the flags passed, additional files may be generated for each file processed:</p> <p>Depending on the flags passed, additional files may be generated for each file processed:</p>
<p>For any schema input files, one or more generators can be specified:</p>
<ul>
<li><code>--cpp</code>, <code>-c</code> : Generate a C++ header for all definitions in this file (as <code>filename_generated.h</code>).</li>
<li><code>--java</code>, <code>-j</code> : Generate Java code.</li>
<li><code>--csharp</code>, <code>-n</code> : Generate C# code.</li>
<li><code>--go</code>, <code>-g</code> : Generate Go code.</li>
<li><code>--python</code>, <code>-p</code>: Generate Python code.</li>
<li><code>--javascript</code>, <code>-s</code>: Generate JavaScript code.</li>
<li><code>--php</code>: Generate PHP code.</li>
</ul>
<p>For any data input files:</p>
<ul>
<li><code>--binary</code>, <code>-b</code> : If data is contained in this file, generate a <code>filename.bin</code> containing the binary flatbuffer (or a different extension if one is specified in the schema).</li>
<li><code>--json</code>, <code>-t</code> : If data is contained in this file, generate a <code>filename.json</code> representing the data in the flatbuffer.</li>
</ul>
<p>Additional options:</p>
<ul> <ul>
<li><code>-c</code> : Generate a C++ header for all definitions in this file (as <code>filename_generated.h</code>). Skipped for data.</li>
<li><code>-j</code> : Generate Java classes. Skipped for data.</li>
<li><code>-n</code> : Generate C# classes. Skipped for data.</li>
<li><code>-g</code> : Generate Go classes. Skipped for data.</li>
<li><code>-b</code> : If data is contained in this file, generate a <code>filename.bin</code> containing the binary flatbuffer.</li>
<li><code>-t</code> : If data is contained in this file, generate a <code>filename.json</code> representing the data in the flatbuffer.</li>
<li><code>-o PATH</code> : 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. <code>/</code> or <code>\</code>.</li> <li><code>-o PATH</code> : 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. <code>/</code> or <code>\</code>.</li>
<li><code>-I PATH</code> : when encountering <code>include</code> 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.</li> <li><code>-I PATH</code> : when encountering <code>include</code> 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.</li>
<li><code>-M</code> : Print make rules for generated files.</li> <li><code>-M</code> : Print make rules for generated files.</li>
@ -86,8 +96,9 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
<li><code>--gen-onefile</code> : Generate single output file (useful for C#)</li> <li><code>--gen-onefile</code> : Generate single output file (useful for C#)</li>
<li><code>--raw-binary</code> : Allow binaries without a file_indentifier to be read. This may crash flatc given a mismatched schema.</li> <li><code>--raw-binary</code> : Allow binaries without a file_indentifier to be read. This may crash flatc given a mismatched schema.</li>
<li><code>--proto</code>: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: <code>package</code>, <code>message</code>, <code>enum</code>, nested declarations, <code>import</code> (use <code>-I</code> for paths), <code>extend</code>, <code>oneof</code>, <code>group</code>. Does not support, but will skip without error: <code>option</code>, <code>service</code>, <code>extensions</code>, and most everything else.</li> <li><code>--proto</code>: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: <code>package</code>, <code>message</code>, <code>enum</code>, nested declarations, <code>import</code> (use <code>-I</code> for paths), <code>extend</code>, <code>oneof</code>, <code>group</code>. Does not support, but will skip without error: <code>option</code>, <code>service</code>, <code>extensions</code>, and most everything else.</li>
<li><code>--schema</code>: 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. </li> <li><code>--schema</code>: 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.</li>
</ul> </ul>
<p>NOTE: short-form options for generators are deprecated, use the long form whenever possible. </p>
</div></div><!-- contents --> </div></div><!-- contents -->
</div><!-- doc-content --> </div><!-- doc-content -->
<!-- Google Analytics --> <!-- Google Analytics -->

View File

@ -2,7 +2,7 @@
Usage: Usage:
flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
[ -- FILES...] [ -- FILES...]
The files are read and parsed in order, and can contain either schemas 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 Depending on the flags passed, additional files may
be generated for each file processed: be generated for each file processed:
- `-c` : Generate a C++ header for all definitions in this file (as For any schema input files, one or more generators can be specified:
`filename_generated.h`). Skipped for data.
- `-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 - `--go`, `-g` : Generate Go code.
`filename.bin` containing the binary flatbuffer.
- `-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. `filename.json` representing the data in the flatbuffer.
Additional options:
- `-o PATH` : Output all generated files to PATH (either absolute, or - `-o PATH` : Output all generated files to PATH (either absolute, or
relative to the current directory). If omitted, PATH will be the relative to the current directory). If omitted, PATH will be the
current directory. PATH should end in your systems path separator, 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 output a binary version of the specified schema that itself corresponds
to the reflection/reflection.fbs schema. Loading this binary file is the to the reflection/reflection.fbs schema. Loading this binary file is the
basis for reflection functionality. basis for reflection functionality.
NOTE: short-form options for generators are deprecated, use the long form
whenever possible.

View File

@ -28,7 +28,8 @@ struct Generator {
const std::string &path, const std::string &path,
const std::string &file_name, const std::string &file_name,
const flatbuffers::GeneratorOptions &opts); const flatbuffers::GeneratorOptions &opts);
const char *generator_opt; const char *generator_opt_short;
const char *generator_opt_long;
const char *lang_name; const char *lang_name;
flatbuffers::GeneratorOptions::Language lang; flatbuffers::GeneratorOptions::Language lang;
const char *generator_help; const char *generator_help;
@ -40,41 +41,41 @@ struct Generator {
}; };
const Generator generators[] = { const Generator generators[] = {
{ flatbuffers::GenerateBinary, "-b", "binary", { flatbuffers::GenerateBinary, "-b", "--binary", "binary",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate wire format binaries for any data definitions", "Generate wire format binaries for any data definitions",
flatbuffers::BinaryMakeRule }, flatbuffers::BinaryMakeRule },
{ flatbuffers::GenerateTextFile, "-t", "text", { flatbuffers::GenerateTextFile, "-t", "--json", "text",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate text output for any data definitions", "Generate text output for any data definitions",
flatbuffers::TextMakeRule }, flatbuffers::TextMakeRule },
{ flatbuffers::GenerateCPP, "-c", "C++", { flatbuffers::GenerateCPP, "-c", "--cpp", "C++",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate C++ headers for tables/structs", "Generate C++ headers for tables/structs",
flatbuffers::CPPMakeRule }, flatbuffers::CPPMakeRule },
{ flatbuffers::GenerateGo, "-g", "Go", { flatbuffers::GenerateGo, "-g", "--go", "Go",
flatbuffers::GeneratorOptions::kGo, flatbuffers::GeneratorOptions::kGo,
"Generate Go files for tables/structs", "Generate Go files for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateGeneral, "-j", "Java", { flatbuffers::GenerateGeneral, "-j", "--java", "Java",
flatbuffers::GeneratorOptions::kJava, flatbuffers::GeneratorOptions::kJava,
"Generate Java classes for tables/structs", "Generate Java classes for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateJS, "-s", "JavaScript", { flatbuffers::GenerateJS, "-s", "--js", "JavaScript",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate JavaScript code for tables/structs", "Generate JavaScript code for tables/structs",
flatbuffers::JSMakeRule }, flatbuffers::JSMakeRule },
{ flatbuffers::GenerateGeneral, "-n", "C#", { flatbuffers::GenerateGeneral, "-n", "--csharp", "C#",
flatbuffers::GeneratorOptions::kCSharp, flatbuffers::GeneratorOptions::kCSharp,
"Generate C# classes for tables/structs", "Generate C# classes for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
{ flatbuffers::GeneratePython, "-p", "Python", { flatbuffers::GeneratePython, "-p", "--python", "Python",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate Python files for tables/structs", "Generate Python files for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
{ flatbuffers::GeneratePhp, "--php", "PHP", { flatbuffers::GeneratePhp, nullptr, "--php", "PHP",
flatbuffers::GeneratorOptions::kMAX, flatbuffers::GeneratorOptions::kMAX,
"Generate Php files for tables/structs", "Generate PHP files for tables/structs",
flatbuffers::GeneralMakeRule }, flatbuffers::GeneralMakeRule },
}; };
@ -86,8 +87,11 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
if (usage) { if (usage) {
printf("usage: %s [OPTION]... FILE... [-- FILE...]\n", program_name); printf("usage: %s [OPTION]... FILE... [-- FILE...]\n", program_name);
for (size_t i = 0; i < sizeof(generators) / sizeof(generators[0]); ++i) for (size_t i = 0; i < sizeof(generators) / sizeof(generators[0]); ++i)
printf(" %s %s.\n", printf(" %-12s %s %s.\n",
generators[i].generator_opt, generators[i].generator_opt_long,
generators[i].generator_opt_short
? generators[i].generator_opt_short
: " ",
generators[i].generator_help); generators[i].generator_help);
printf( printf(
" -o PATH Prefix PATH to all generated files.\n" " -o PATH Prefix PATH to all generated files.\n"
@ -179,7 +183,9 @@ int main(int argc, const char *argv[]) {
print_make_rules = true; print_make_rules = true;
} else { } else {
for (size_t i = 0; i < num_generators; ++i) { 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; generator_enabled[i] = true;
any_generator = true; any_generator = true;
goto found; goto found;

View File

@ -1,2 +1,2 @@
../flatc -c -j -n -g -b -p -s --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json ../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
../flatc -b --schema monster_test.fbs ../flatc --binary --schema monster_test.fbs

Binary file not shown.

View File

@ -352,6 +352,8 @@ MyGame.Example.Stat.endStat = function(builder) {
}; };
/** /**
* an example documentation comment: monster object
*
* @constructor * @constructor
*/ */
MyGame.Example.Monster = function() { MyGame.Example.Monster = function() {