cmd:opts: New -a (sense-api shlibs) and -p (api shlib search dir) opts
This commit is contained in:
@@ -18,6 +18,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::string senseApiLibPath;
|
std::string senseApiLibPath;
|
||||||
|
std::vector<std::string> senseApiLibs;
|
||||||
std::string deviceSpecs;
|
std::string deviceSpecs;
|
||||||
std::vector<std::string> deviceSpecFiles;
|
std::vector<std::string> deviceSpecFiles;
|
||||||
bool verbose, printUsage;
|
bool verbose, printUsage;
|
||||||
|
|||||||
+41
-2
@@ -4,6 +4,7 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
struct option OptionParser::longOptions[] = {
|
struct option OptionParser::longOptions[] = {
|
||||||
{"devicespec", required_argument, 0, 's'},
|
{"devicespec", required_argument, 0, 's'},
|
||||||
@@ -11,6 +12,9 @@ struct option OptionParser::longOptions[] = {
|
|||||||
{"devspec", required_argument, 0, 's'},
|
{"devspec", required_argument, 0, 's'},
|
||||||
{"devfile", required_argument, 0, 'd'},
|
{"devfile", required_argument, 0, 'd'},
|
||||||
{"devicefile", required_argument, 0, 'd'},
|
{"devicefile", required_argument, 0, 'd'},
|
||||||
|
{"sense-api-lib", required_argument, 0, 'a'},
|
||||||
|
{"senseapi", required_argument, 0, 'a'},
|
||||||
|
{"sense-api-path", required_argument, 0, 'p'},
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", no_argument, 0, 'v'},
|
||||||
{"help", no_argument, 0, '?'},
|
{"help", no_argument, 0, '?'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
@@ -22,7 +26,7 @@ void OptionParser::parseArguments(int argc, char *argv[])
|
|||||||
int optionIndex = 0;
|
int optionIndex = 0;
|
||||||
optind = 1; // Reset optind to 1 before parsing
|
optind = 1; // Reset optind to 1 before parsing
|
||||||
while ((opt = getopt_long(
|
while ((opt = getopt_long(
|
||||||
argc, argv, "s:d:v?", longOptions, &optionIndex)) != -1)
|
argc, argv, "s:d:a:p:v?", longOptions, &optionIndex)) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
@@ -35,6 +39,30 @@ void OptionParser::parseArguments(int argc, char *argv[])
|
|||||||
case 'd':
|
case 'd':
|
||||||
deviceSpecFiles.push_back(optarg);
|
deviceSpecFiles.push_back(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'a':
|
||||||
|
senseApiLibs.push_back(optarg);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
|
||||||
|
if (!senseApiLibPath.empty())
|
||||||
|
{
|
||||||
|
std::cerr << std::string(__func__)
|
||||||
|
+ " - Overwriting previous sense-api-path with: " << optarg
|
||||||
|
<< '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat(optarg, &info) != 0 || !(info.st_mode & S_IFDIR))
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(
|
||||||
|
std::string(__func__) + " - The specified path is not a "
|
||||||
|
"directory: " + optarg);
|
||||||
|
}
|
||||||
|
|
||||||
|
senseApiLibPath = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
@@ -42,7 +70,9 @@ void OptionParser::parseArguments(int argc, char *argv[])
|
|||||||
printUsage = true;
|
printUsage = true;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
throw std::invalid_argument("Invalid argument encountered: " + std::string(argv[optind - 1]));
|
throw std::invalid_argument(
|
||||||
|
std::string(__func__) + " - Invalid argument encountered: "
|
||||||
|
+ std::string(argv[optind - 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +81,8 @@ std::string OptionParser::getUsage() const
|
|||||||
{
|
{
|
||||||
return "Usage: program [-s|--devicespec|--spec|--devspec <device_spec>] "
|
return "Usage: program [-s|--devicespec|--spec|--devspec <device_spec>] "
|
||||||
"[-d|--devfile|--devicefile <filename>] "
|
"[-d|--devfile|--devicefile <filename>] "
|
||||||
|
"[-a|--sense-api-lib|--senseapi <filename>] "
|
||||||
|
"[-p|--sense-api-path <directory>] "
|
||||||
"[-v|--verbose] "
|
"[-v|--verbose] "
|
||||||
"[-?|--help]";
|
"[-?|--help]";
|
||||||
}
|
}
|
||||||
@@ -68,4 +100,11 @@ void OptionParser::dumpOptions() const
|
|||||||
std::cout << file << " ";
|
std::cout << file << " ";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Sense API Library Path: " << senseApiLibPath << std::endl;
|
||||||
|
std::cout << "Sense API Libraries: ";
|
||||||
|
for (const auto& lib : senseApiLibs) {
|
||||||
|
std::cout << lib << " ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user