thiru-mg commented on code in PR #3286:
URL: https://github.com/apache/avro/pull/3286#discussion_r1910619817
##########
lang/c++/impl/avrogencpp.cc:
##########
@@ -875,49 +872,104 @@ static string readGuard(const string &filename) {
return candidate;
}
+struct ProgramOptions {
+ bool helpRequested = false;
+ bool versionRequested = false;
+ bool noUnionTypedef = false;
+ std::string includePrefix = "avro";
+ std::string nameSpace;
+ std::string inputFile;
+ std::string outputFile;
+};
+
+static void printUsage() {
+ std::cout << "Allowed options:\n"
+ << " -h [ --help ] produce help message\n"
+ << " -V [ --version ] produce version
information\n"
+ << " -p [ --include-prefix ] arg (=avro) prefix for include
headers, - for none, default: avro\n"
+ << " -U [ --no-union-typedef ] do not generate
typedefs for unions in records\n"
+ << " -n [ --namespace ] arg set namespace for
generated code\n"
+ << " -i [ --input ] arg input file\n"
+ << " -o [ --output ] arg output file to
generate\n";
+}
+
+static bool parseArgs(int argc, char **argv, ProgramOptions &opts) {
+ for (int i = 1; i < argc; ++i) {
+ std::string arg = argv[i];
+
+ if (arg == "-h" || arg == "--help") {
+ opts.helpRequested = true;
+ return true;
+ }
+
+ if (arg == "-V" || arg == "--version") {
+ opts.versionRequested = true;
+ return true;
+ }
+
+ if (arg == "-U" || arg == "--no-union-typedef") {
+ opts.noUnionTypedef = true;
+ } else if (arg == "-p" || arg == "--include-prefix") {
+ if (i + 1 >= argc) {
Review Comment:
Instead of repeating the error display multiple times, we can use:
if (i + 1 < argc) {
opts.includePrefix = argv[++i];
continue;
}
And add at the end of the loop body (so that it executes if the condition is
not met):
std::cerr << "Missing value for option: " << arg <<
std::endl;
return false;
##########
lang/c++/impl/avrogencpp.cc:
##########
@@ -875,49 +872,104 @@ static string readGuard(const string &filename) {
return candidate;
}
+struct ProgramOptions {
+ bool helpRequested = false;
+ bool versionRequested = false;
+ bool noUnionTypedef = false;
+ std::string includePrefix = "avro";
+ std::string nameSpace;
+ std::string inputFile;
+ std::string outputFile;
+};
+
+static void printUsage() {
+ std::cout << "Allowed options:\n"
+ << " -h [ --help ] produce help message\n"
+ << " -V [ --version ] produce version
information\n"
+ << " -p [ --include-prefix ] arg (=avro) prefix for include
headers, - for none, default: avro\n"
+ << " -U [ --no-union-typedef ] do not generate
typedefs for unions in records\n"
+ << " -n [ --namespace ] arg set namespace for
generated code\n"
+ << " -i [ --input ] arg input file\n"
+ << " -o [ --output ] arg output file to
generate\n";
+}
+
+static bool parseArgs(int argc, char **argv, ProgramOptions &opts) {
+ for (int i = 1; i < argc; ++i) {
+ std::string arg = argv[i];
+
+ if (arg == "-h" || arg == "--help") {
+ opts.helpRequested = true;
+ return true;
+ }
+
+ if (arg == "-V" || arg == "--version") {
Review Comment:
Should we also check if there are any more arguments? For example, if
someone type `avrogencpp -V -U`, should we just show the version or error out?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]