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