{ "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." },
+ { "h", "help", "", "Prints this help text and exit." },
{ "", "string-json", "",
"Strict JSON: field names must be / will be quoted, no trailing commas in "
"tables/vectors." },
{ "", "reflect-types", "",
"Add minimal type reflection to code generation." },
{ "", "reflect-names", "", "Add minimal type/name reflection." },
- { "", "rust-serialize", "", "Implement serde::Serialize on generated Rust types." },
+ { "", "rust-serialize", "",
+ "Implement serde::Serialize on generated Rust types." },
{ "", "root-type", "T", "Select or override the default root_type." },
{ "", "require-explicit-ids", "",
"When parsing schemas, require explicit ids (id: x)." },
ss << "\n";
}
+static void AppendShortOption(std::stringstream &ss,
+ const FlatCOption &option) {
+ if (!option.short_opt.empty()) {
+ ss << "-" << option.short_opt;
+ if (!option.long_opt.empty()) { ss << "|"; }
+ }
+ if (!option.long_opt.empty()) { ss << "--" << option.long_opt; }
+}
+
+std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
+ std::stringstream ss;
+ ss << "Usage: " << program_name << " [";
+ for (size_t i = 0; i < params_.num_generators; ++i) {
+ const Generator &g = params_.generators[i];
+ AppendShortOption(ss, g.option);
+ ss << ", ";
+ }
+ for (const FlatCOption &option : options) {
+ AppendShortOption(ss, option);
+ ss << ", ";
+ }
+ ss.seekp(-2, ss.cur);
+ ss << "]... FILE... [-- FILE...]";
+ std::string help = ss.str();
+ std::stringstream ss_textwrap;
+ AppendTextWrappedString(ss_textwrap, help, 80, 0);
+ return ss_textwrap.str();
+}
+
std::string FlatCompiler::GetUsageString(const char *program_name) const {
std::stringstream ss;
ss << "Usage: " << program_name << " [OPTION]... FILE... [-- FILE...]\n";
return 0;
}
+ if (argc <= 1) { Error("Need to provide at least one argument."); }
+
flatbuffers::IDLOptions opts;
std::string output_path;
} else if (arg == "--version") {
printf("flatc version %s\n", FLATC_VERSION());
exit(0);
- } else if (arg == "--help") {
+ } else if (arg == "--help" || arg == "-h") {
printf("%s\n", GetUsageString(program_name).c_str());
exit(0);
} else if (arg == "--grpc") {
* limitations under the License.
*/
+#include <cstdio>
#include <memory>
#include "bfbs_gen_lua.h"
const std::string &warn, bool show_exe_name) {
(void)flatc;
if (show_exe_name) { printf("%s: ", g_program_name); }
- fprintf(stderr, "warning:\n %s\n\n", warn.c_str());
+ fprintf(stderr, "\nwarning:\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); }
if (usage && flatc) {
- fprintf(stderr, "%s\n", flatc->GetUsageString(g_program_name).c_str());
+ fprintf(stderr, "%s\n", flatc->GetShortUsageString(g_program_name).c_str());
}
- fprintf(stderr, "error:\n %s\n\n", err.c_str());
+ fprintf(stderr, "\nerror:\n %s\n\n", err.c_str());
exit(1);
}