Add --force-defaults option to flatc [C++, parser] (#4729)

* Add --force-defaults option to flatc

To emit default values for fields which are not present or which are set
to the default value.

* flatc option --force-defaults should have a default value (false) and take action on the builder_ within the Parser constructor

* Add help text from flatc --force-defaults to Compiler.md doc

* Clarified docs for flatc --force-defaults, and imply that this behaviour is not normally needed.

* Updated docs and flatc help text for --force-defaults option
This commit is contained in:
Paul Reimer
2018-06-27 09:12:52 -07:00
committed by Wouter van Oortmerssen
parent e9912e9298
commit 741c63052d
3 changed files with 10 additions and 0 deletions

View File

@@ -122,6 +122,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" --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"
" --force-defaults Emit default values in binary output from JSON\n"
"FILEs may be schemas (must end in .fbs), or JSON files (conforming to preceding\n"
"schema). FILEs after the -- must be binary flatbuffer format files.\n"
"Output files are named using the base file name of the input,\n"
@@ -277,6 +278,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
} else if (arg == "--root-type") {
if (++argi >= argc) Error("missing type following" + arg, true);
opts.root_type = argv[argi];
} else if (arg == "--force-defaults") {
opts.force_defaults = true;
} else {
for (size_t i = 0; i < params_.num_generators; ++i) {
if (arg == params_.generators[i].generator_opt_long ||