28 #include <SimoxUtility/algorithm/string/string_tools.h>
38 options.
error =
false;
40 options.
print =
false;
47 options.
description.reset(
new options_description(std::string(
48 "This executable is an application within the ArmarX framework.\n")
49 +
"==================================================================\n"
50 +
" Starting an ArmarX Scenario\n"
51 +
"==================================================================\n"
52 +
"In order to start a Scenario pass either a path to an scx file or a Scenario name with a command."
53 +
" Example command:\n\n"
55 +
" > armarx scenario command scxpath/scxname [package name] [-a application]\n\n"
60 options.
description->add_options()(
"help,h",
"Help option");
62 options.
description->add_options()(
"command,c", value <std::string>(),
"What should be done: {\n \tstart, \n \tdeploy, \n \tstop, \n \tkill, \n \tremove, \n \trestart (kills by default), \n \tlist (List all Scenario in Packages in ArmarX.DefaultPackages)\n \tstatus (Show the status of the Scenario)\n \t generate (generate the old local/remote icegrid xml configs)\n}");
63 options.
description->add_options()(
"file,f", value <std::string>()->default_value(
"."),
"Path to the scx file (default: looks in current dir)");
64 options.
description->add_options()(
"package,p", value<std::string>(),
"[optional] If the packages are included in your default config as ArmarX.DefaultPackages this can be left empty");
65 options.
description->add_options()(
"application,a", value<std::string>(),
"[optional] Application out of the Scenario to execute the command with");
66 options.
description->add_options()(
"parameters", value<std::string>()->default_value(
""),
"[optional] Use this if you want to start an scenario with additional commandline parameters");
67 options.
description->add_options()(
"print",
"Print the execution commands of the CLI instead of executing them");
68 options.
description->add_options()(
"wait,w",
"Wait for all applications to quit before exiting");
69 options.
description->add_options()(
"remote",
"[optional] if you want to deploy an Scenario remotely this has to be added to the command");
71 positional_options_description pd;
75 pd.add(
"application", 1);
78 store(command_line_parser(argc, argv).options(*options.
description).positional(pd).allow_unregistered().run(), vm);
89 options.
scxPath = vm[
"file"].as<std::string>();;
92 if (vm.count(
"command"))
94 options.
command = vm[
"command"].as<std::string>();
100 && options.
command !=
"restart"
102 && options.
command !=
"generate"
106 && options.
command !=
"periodic_status"
109 options.
error =
true;
113 if (vm.count(
"package"))
115 options.
packageName = vm[
"package"].as<std::string>();
118 if (vm.count(
"application"))
123 if (vm.count(
"parameters"))
125 options.
parameters = vm[
"parameters"].as<std::string>();
127 if (vm.count(
"print"))
129 options.
print =
true;
131 if (vm.count(
"wait"))
135 if (vm.count(
"remote"))
142 options.
error =
true;
151 if (!errorMessage.empty())
165 std::filesystem::path boostScxPath(options.
scxPath);
167 if (std::filesystem::exists(boostScxPath))
169 if (std::filesystem::is_regular_file(boostScxPath))
171 return boostScxPath.stem().string();
173 else if (std::filesystem::is_directory(boostScxPath))
175 std::vector< std::string > all_matching_files;
177 std::filesystem::directory_iterator end_itr;
178 for (std::filesystem::directory_iterator i(boostScxPath.string()); i != end_itr; ++i)
181 if (!std::filesystem::is_regular_file(i->status()))
186 if (!(i->path().extension() ==
".scx"))
192 all_matching_files.push_back(i->path().stem().string());
195 if (all_matching_files.size() == 0)
199 else if (all_matching_files.size() == 1)
201 return all_matching_files[0];
205 std::cout <<
"Warning: found multiple scx files in this directory choosing " << all_matching_files[0];
206 return all_matching_files[0];