mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +00:00
Add --root-type option to flatc [C++, parser, JSON] (#4728)
* Add --root-type option to flatc To select or override a root_type * Add help text from flatc --root-type to Compiler.md doc
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
d215852f52
commit
6621424308
@@ -120,6 +120,7 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
" --no-ts-reexport Don't re-export imported dependencies for TypeScript.\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"
|
||||
"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"
|
||||
@@ -268,6 +269,9 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
opts.mini_reflect = IDLOptions::kTypes;
|
||||
} else if (arg == "--reflect-names") {
|
||||
opts.mini_reflect = IDLOptions::kTypesAndNames;
|
||||
} else if (arg == "--root-type") {
|
||||
if (++argi >= argc) Error("missing type following" + arg, true);
|
||||
opts.root_type = argv[argi];
|
||||
} else {
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (arg == params_.generators[i].generator_opt_long ||
|
||||
@@ -407,6 +411,13 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts.root_type.empty()) {
|
||||
if (!parser->SetRootType(opts.root_type.c_str()))
|
||||
Error("unknown root type: " + opts.root_type);
|
||||
else if (parser->root_struct_def_->fixed)
|
||||
Error("root type must be a table");
|
||||
}
|
||||
|
||||
if (opts.proto_mode) GenerateFBS(*parser.get(), output_path, filebase);
|
||||
|
||||
// We do not want to generate code for the definitions in this file
|
||||
|
||||
Reference in New Issue
Block a user