cmdopts: Add --interceptor, --extrospector, --actuator and --devicefile
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#include <opts.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <getopt.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct option OptionParser::longOptions[] = {
|
||||
{"extro", required_argument, 0, 'e'},
|
||||
{"extrospector", required_argument, 0, 'e'},
|
||||
{"intero", required_argument, 0, 'i'},
|
||||
{"interoceptor", required_argument, 0, 'i'},
|
||||
{"act", required_argument, 0, 'a'},
|
||||
{"actuator", required_argument, 0, 'a'},
|
||||
{"devfile", required_argument, 0, 'd'},
|
||||
{"devicefile", required_argument, 0, 'd'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
void OptionParser::parseArguments(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
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)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'e':
|
||||
extro.push_back(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
intero.push_back(optarg);
|
||||
break;
|
||||
case 'a':
|
||||
actuator.push_back(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
devFile = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("Invalid argument encountered: " + std::string(argv[optind - 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string OptionParser::getUsage() const
|
||||
{
|
||||
return "Usage: program [-e|--extro|--extrospector <sensor_dev_spec>] "
|
||||
"[-i|--intero|--interoceptor <sensor_dev_spec>] "
|
||||
"[-a|--act|--actuator <actuator_dev_spec>] "
|
||||
"[-d|--devfile|--devicefile <filename>] "
|
||||
"[-v|--verbose]";
|
||||
}
|
||||
|
||||
void OptionParser::dumpOptions() const
|
||||
{
|
||||
if (verbose) {
|
||||
std::cout << "Verbose mode is on" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Extro: ";
|
||||
for (const auto& extro : extro) {
|
||||
std::cout << extro << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Intero: ";
|
||||
for (const auto& intero : intero) {
|
||||
std::cout << intero << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Actuator: ";
|
||||
for (const auto& actuator : actuator) {
|
||||
std::cout << actuator << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Dev file: " << devFile << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user