Cmdline: Suppress getopt stderr msg, bubble exception upward instead
This commit is contained in:
@@ -46,7 +46,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
|||||||
catch (const std::invalid_argument& e)
|
catch (const std::invalid_argument& e)
|
||||||
{
|
{
|
||||||
std::cerr << __func__ << ": Exception occurred: " << e.what()
|
std::cerr << __func__ << ": Exception occurred: " << e.what()
|
||||||
<< '\n' << options.getUsage() << '\n';
|
<< '\n';
|
||||||
|
|
||||||
options.printUsage = true;
|
options.printUsage = true;
|
||||||
mrntt::exitCode = EXIT_FAILURE;
|
mrntt::exitCode = EXIT_FAILURE;
|
||||||
|
|||||||
+6
-5
@@ -22,7 +22,7 @@ struct option OptionParser::longOptions[] = {
|
|||||||
{"apipath", required_argument, 0, 'p'},
|
{"apipath", required_argument, 0, 'p'},
|
||||||
{"libpath", required_argument, 0, 'p'},
|
{"libpath", required_argument, 0, 'p'},
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", no_argument, 0, 'v'},
|
||||||
{"help", no_argument, 0, '?'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,8 +35,9 @@ void OptionParser::parseArguments(int argc, char *argv[], char **envp)
|
|||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
|
|
||||||
optind = 1; // Reset optind to 1 before parsing
|
optind = 1; // Reset optind to 1 before parsing
|
||||||
|
opterr = 0;
|
||||||
while ((opt = getopt_long(
|
while ((opt = getopt_long(
|
||||||
argc, argv, "s:d:a:p:v?", longOptions, &optionIndex)) != -1)
|
argc, argv, "s:d:a:p:vh?", longOptions, &optionIndex)) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
@@ -69,10 +70,10 @@ void OptionParser::parseArguments(int argc, char *argv[], char **envp)
|
|||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case 'h':
|
||||||
printUsage = true;
|
printUsage = true;
|
||||||
return;
|
return;
|
||||||
default:
|
case '?':
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
std::string(__func__) + " - Invalid argument encountered: "
|
std::string(__func__) + " - Invalid argument encountered: "
|
||||||
+ std::string(argv[optind - 1]));
|
+ std::string(argv[optind - 1]));
|
||||||
@@ -87,7 +88,7 @@ std::string OptionParser::getUsage() const
|
|||||||
"[-a|--api-lib|--apilib|--api|--lib <filename>] "
|
"[-a|--api-lib|--apilib|--api|--lib <filename>] "
|
||||||
"[-p|--api-lib-path|--apipath|--libpath <directory>] "
|
"[-p|--api-lib-path|--apipath|--libpath <directory>] "
|
||||||
"[-v|--verbose] "
|
"[-v|--verbose] "
|
||||||
"[-?|--help]";
|
"[-h|--help]";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string OptionParser::stringifyOptions(void) const
|
std::string OptionParser::stringifyOptions(void) const
|
||||||
|
|||||||
Reference in New Issue
Block a user