mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-07-12 19:01:50 +02:00
moved optstring and long options to the constructor
This commit is contained in:
@ -11,6 +11,10 @@
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
CommandLineOptions::CommandLineOptions(AppType app)
|
||||
: appType_(app), optString_(buildOptString()),
|
||||
longOptions_(buildOptionList()) {}
|
||||
|
||||
/** for testing */
|
||||
ParsedOptions CommandLineOptions::parse(const std::vector<std::string> &args) {
|
||||
std::vector<char *> argv;
|
||||
@ -28,13 +32,11 @@ ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
|
||||
FrameSyncOptions frame;
|
||||
base.port = DEFAULT_TCP_RX_PORTNO;
|
||||
|
||||
auto optString = buildOptString();
|
||||
auto longOptions = buildOptionList();
|
||||
optind = 0; // reset getopt
|
||||
int opt, option_index = 0;
|
||||
|
||||
while ((opt = getopt_long(argc, argv, optString.c_str(), longOptions.data(),
|
||||
&option_index)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, optString_.c_str(),
|
||||
longOptions_.data(), &option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
case 'h':
|
||||
|
@ -33,7 +33,7 @@ using ParsedOptions =
|
||||
|
||||
class CommandLineOptions {
|
||||
public:
|
||||
constexpr explicit CommandLineOptions(AppType app) : appType_(app) {}
|
||||
explicit CommandLineOptions(AppType app);
|
||||
ParsedOptions parse(const std::vector<std::string> &args); // for testing
|
||||
ParsedOptions parse(int argc, char *argv[]);
|
||||
std::string getTypeString() const;
|
||||
@ -46,6 +46,8 @@ class CommandLineOptions {
|
||||
|
||||
private:
|
||||
AppType appType_;
|
||||
std::string optString_;
|
||||
std::vector<option> longOptions_;
|
||||
std::vector<option> buildOptionList() const;
|
||||
std::string buildOptString() const;
|
||||
|
||||
|
Reference in New Issue
Block a user