Cmdline: Suppress getopt stderr msg, bubble exception upward instead

This commit is contained in:
2025-08-03 10:19:22 -04:00
parent fef73692f7
commit e836b2bf32
2 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
catch (const std::invalid_argument& e)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< '\n' << options.getUsage() << '\n';
<< '\n';
options.printUsage = true;
mrntt::exitCode = EXIT_FAILURE;
+6 -5
View File
@@ -22,7 +22,7 @@ struct option OptionParser::longOptions[] = {
{"apipath", required_argument, 0, 'p'},
{"libpath", required_argument, 0, 'p'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -35,8 +35,9 @@ void OptionParser::parseArguments(int argc, char *argv[], char **envp)
argv0 = argv[0];
optind = 1; // Reset optind to 1 before parsing
opterr = 0;
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)
{
@@ -69,10 +70,10 @@ void OptionParser::parseArguments(int argc, char *argv[], char **envp)
case 'v':
verbose = true;
break;
case '?':
case 'h':
printUsage = true;
return;
default:
case '?':
throw std::invalid_argument(
std::string(__func__) + " - Invalid argument encountered: "
+ std::string(argv[optind - 1]));
@@ -87,7 +88,7 @@ std::string OptionParser::getUsage() const
"[-a|--api-lib|--apilib|--api|--lib <filename>] "
"[-p|--api-lib-path|--apipath|--libpath <directory>] "
"[-v|--verbose] "
"[-?|--help]";
"[-h|--help]";
}
std::string OptionParser::stringifyOptions(void) const