DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CommandLineInterpreter.hpp
Go to the documentation of this file.
1
12#ifndef APPFWK_SRC_COMMANDLINEINTERPRETER_HPP_
13#define APPFWK_SRC_COMMANDLINEINTERPRETER_HPP_
14
15#include "boost/program_options.hpp"
16
17#include <iostream>
18#include <string>
19#include <vector>
20
21namespace bpo = boost::program_options;
22
23namespace dunedaq::appfwk {
32{
33public:
40 static CommandLineInterpreter parse(int argc, char** argv)
41 {
43
44 std::ostringstream descstr;
45 descstr << *argv
46 << " known arguments (additional arguments will be stored and "
47 "passed on)";
48 bpo::options_description desc(descstr.str());
49 desc.add_options()("name,n", bpo::value<std::string>()->required(), "Application name")(
50 "sessionName,s", bpo::value<std::string>()->required(), "Session name")(
51 "configurationId,k", bpo::value<std::string>()->required(), "Configuration id")(
52 "commandFacility,c", bpo::value<std::string>()->required(), "CommandFacility URI")(
53 "configurationService,d", bpo::value<std::string>()->required(), "Configuration Service URI")(
54 "help,h", "produce help message");
55
56 bpo::variables_map vm;
57 auto parsed = bpo::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
58
59 output.other_options = bpo::collect_unrecognized(parsed.options, bpo::include_positional);
60 bpo::store(parsed, vm);
61
62 if (vm.count("help")) {
63 std::cout << desc << std::endl; // NOLINT
64 output.help_requested = true;
65 return output;
66 }
67
68 bpo::notify(vm);
69
70 output.app_name = vm["name"].as<std::string>();
71 output.session_name = vm["sessionName"].as<std::string>();
72 output.configuration_id = vm["configurationId"].as<std::string>();
73 output.command_facility_plugin_name = vm["commandFacility"].as<std::string>();
74 output.conf_service_plugin_name = vm["configurationService"].as<std::string>();
75 return output;
76 }
77
78 bool help_requested{ false };
79
80 std::string app_name{ "" };
81 std::string session_name{ "" };
82 std::string configuration_id{ "" };
84 std::string conf_service_plugin_name{ "" };
85
86 std::vector<std::string> other_options{};
87};
88} // namespace dunedaq::appfwk
89
90#endif // APPFWK_SRC_COMMANDLINEINTERPRETER_HPP_
CommandLineInterpreter parses the command-line options given to the application and stores the result...
std::vector< std::string > other_options
Any other options which were passed and not recognized.
static CommandLineInterpreter parse(int argc, char **argv)
Parse the command line and return a CommandLineInterpreter struct.