9 #include <boost/filesystem/operations.hpp> 10 #include <boost/filesystem/path.hpp> 11 #include <boost/program_options/options_description.hpp> 12 #include <boost/program_options/parsers.hpp> 18 namespace bpo = boost::program_options;
22 namespace topology_cmd
42 ,
m_sid(boost::uuids::nil_uuid())
56 if (
nullptr == _options)
57 throw std::runtime_error(
"Internal error: options' container is empty.");
60 bpo::options_description options(
"dds-agent-cmd options");
61 options.add_options()(
"help,h",
"Produce help message");
62 options.add_options()(
"version,v",
"Version information");
63 options.add_options()(
"session,s", bpo::value<std::string>(),
"DDS Session ID");
64 options.add_options()(
"update,u",
66 "Define a topology to update currently active topology.");
67 options.add_options()(
"disable-validation",
69 "Disable topology valiadation.");
70 options.add_options()(
"activate",
72 "Request to activate agents, i.e. distribute and start user tasks.");
73 options.add_options()(
"stop",
"Request to stop execution of user tasks.");
74 options.add_options()(
"validate",
76 "Validate topology file against XSD schema.");
77 options.add_options()(
"required-agents",
79 "Get the required number of agents for the topology.");
80 options.add_options()(
81 "topology-name", bpo::value<std::string>(&_options->
m_sTopoFile),
"Get the name of the topology.");
82 options.add_options()(
"verbose,V",
"Verbose output");
85 bpo::variables_map vm;
86 bpo::store(bpo::command_line_parser(_argc, _argv).options(options).run(), vm);
93 if (vm.count(
"help") || vm.empty())
98 if (vm.count(
"version"))
103 if (vm.count(
"session"))
104 _options->
m_sid = boost::uuids::string_generator()(vm[
"session"].as<std::string>());
105 if (vm.count(
"verbose"))
111 if (!vm.count(
"activate") && !vm.count(
"update") && !vm.count(
"required-agents") &&
112 !vm.count(
"topology-name"))
114 throw std::runtime_error(
"--disable-validation must be used together with --activate, --update, " 115 "--required-agents or --topology-name");
118 if (vm.count(
"validate") && !_options->
m_sTopoFile.empty())
122 boost::filesystem::path pathTopoFile(_options->
m_sTopoFile);
123 _options->
m_sTopoFile = boost::filesystem::absolute(pathTopoFile).string();
126 if (vm.count(
"required-agents") && !_options->
m_sTopoFile.empty())
130 boost::filesystem::path pathTopoFile(_options->
m_sTopoFile);
131 _options->
m_sTopoFile = boost::filesystem::absolute(pathTopoFile).string();
134 if (vm.count(
"topology-name") && !_options->
m_sTopoFile.empty())
138 boost::filesystem::path pathTopoFile(_options->
m_sTopoFile);
139 _options->
m_sTopoFile = boost::filesystem::absolute(pathTopoFile).string();
142 if (vm.count(
"update") || vm.count(
"activate"))
145 if (!boost::filesystem::exists(_options->
m_sTopoFile))
147 std::string sMsg(
"Can't find the topo file: ");
149 throw std::runtime_error(sMsg);
152 if (vm.count(
"update"))
156 else if (vm.count(
"activate"))
161 boost::filesystem::path pathTopoFile(_options->
m_sTopoFile);
162 _options->
m_sTopoFile = boost::filesystem::absolute(pathTopoFile).string();
165 else if (vm.count(
"stop"))
void conflicting_options(const boost::program_options::variables_map &_vm, const char *_opt1, const char *_opt2)
The conflicting_options function used to check that 'opt1' and 'opt2' are not specified at the same t...
Definition: BoostHelper.h:40
ETopologyCmdType m_topologyCmd
Definition: dds-topology/src/Options.h:46
struct dds::topology_cmd::SOptions SOptions_t
dds-agent-cmd's container of options
boost::uuids::uuid m_sid
Definition: dds-topology/src/Options.h:50
#define LOG(severity)
Definition: Logger.h:34
SOptions()
Definition: dds-topology/src/Options.h:38
bool m_verbose
Definition: dds-topology/src/Options.h:48
bool ParseCmdLine(int _argc, char *_argv[], SOptions *_options)
Definition: dds-topology/src/Options.h:54
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
ETopologyCmdType
Definition: dds-topology/src/Options.h:24
dds-agent-cmd's container of options
Definition: dds-topology/src/Options.h:36
std::string m_sTopoFile
Definition: dds-topology/src/Options.h:47
bool m_bDisableValidation
Definition: dds-topology/src/Options.h:49