cmdopts: Add a -?/--help option

This commit is contained in:
2025-01-05 13:35:14 -04:00
parent 77a19deb8e
commit 00ce114d40
3 changed files with 15 additions and 7 deletions
+7 -2
View File
@@ -15,6 +15,7 @@ struct option OptionParser::longOptions[] = {
{"devfile", required_argument, 0, 'd'},
{"devicefile", required_argument, 0, 'd'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
};
@@ -24,7 +25,7 @@ void OptionParser::parseArguments(int argc, char *argv[])
int optionIndex = 0;
optind = 1; // Reset optind to 1 before parsing
while ((opt = getopt_long(
argc, argv, "e:i:a:d:v", longOptions, &optionIndex)) != -1)
argc, argv, "e:i:a:d:v?", longOptions, &optionIndex)) != -1)
{
switch (opt)
{
@@ -43,6 +44,9 @@ void OptionParser::parseArguments(int argc, char *argv[])
case 'v':
verbose = true;
break;
case '?':
printUsage = true;
return;
default:
throw std::invalid_argument("Invalid argument encountered: " + std::string(argv[optind - 1]));
}
@@ -55,7 +59,8 @@ std::string OptionParser::getUsage() const
"[-i|--intero|--interoceptor <sensor_dev_spec>] "
"[-a|--act|--actuator <actuator_dev_spec>] "
"[-d|--devfile|--devicefile <filename>] "
"[-v|--verbose]";
"[-v|--verbose] "
"[-?|--help]";
}
void OptionParser::dumpOptions() const