28 #include <SimoxUtility/algorithm/string/string_tools.h>
38 options.
error =
false;
40 options.
print =
false;
46 options.
description.reset(
new options_description(std::string(
47 "This executable is an application within the ArmarX framework.\n")
48 +
"==================================================================\n"
49 +
" Starting an ArmarX Scenario\n"
50 +
"==================================================================\n"
51 +
"In order to start a Scenario pass either a path to an scx file or a Scenario name with a command."
52 +
" Example command:\n\n"
54 +
" > armarx scenario command scxpath/scxname [package name] [-a application]\n\n"
59 options.
description->add_options()(
"help,h",
"Help option");
61 options.
description->add_options()(
"command,c", value <std::string>(),
"What should be done: {\n \tstart, \n \tstop, \n \tkill, \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}");
62 options.
description->add_options()(
"file,f", value <std::string>()->default_value(
"."),
"Path to the scx file (default: looks in current dir)");
63 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");
64 options.
description->add_options()(
"application,a", value<std::string>(),
"[optional] Application out of the Scenario to execute the command with");
65 options.
description->add_options()(
"parameters", value<std::string>()->default_value(
""),
"[optional] Use this if you want to start an scenario with additional commandline parameters");
66 options.
description->add_options()(
"print",
"Print the execution commands of the CLI instead of executing them");
67 options.
description->add_options()(
"wait,w",
"Wait for all applications to quit before exiting");
69 positional_options_description pd;
73 pd.add(
"application", 1);
76 store(command_line_parser(argc, argv).options(*options.
description).positional(pd).allow_unregistered().run(), vm);
87 options.
scxPath = vm[
"file"].as<std::string>();;
90 if (vm.count(
"command"))
92 options.
command = vm[
"command"].as<std::string>();
100 && options.
command !=
"generate"
102 && options.
command !=
"periodic_status"
105 options.
error =
true;
109 if (vm.count(
"package"))
111 options.
packageName = vm[
"package"].as<std::string>();
114 if (vm.count(
"application"))
119 if (vm.count(
"parameters"))
121 options.
parameters = vm[
"parameters"].as<std::string>();
123 if (vm.count(
"print"))
125 options.
print =
true;
127 if (vm.count(
"wait"))
134 options.
error =
true;
143 if (!errorMessage.empty())
157 std::filesystem::path boostScxPath(options.
scxPath);
159 if (std::filesystem::exists(boostScxPath))
161 if (std::filesystem::is_regular_file(boostScxPath))
163 return boostScxPath.stem().string();
165 else if (std::filesystem::is_directory(boostScxPath))
167 std::vector< std::string > all_matching_files;
169 std::filesystem::directory_iterator end_itr;
170 for (std::filesystem::directory_iterator i(boostScxPath.string()); i != end_itr; ++i)
173 if (!std::filesystem::is_regular_file(i->status()))
178 if (!(i->path().extension() ==
".scx"))
184 all_matching_files.push_back(i->path().stem().string());
187 if (all_matching_files.size() == 0)
191 else if (all_matching_files.size() == 1)
193 return all_matching_files[0];
197 std::cout <<
"Warning: found multiple scx files in this directory choosing " << all_matching_files[0];
198 return all_matching_files[0];