31 #include <SimoxUtility/algorithm/string/string_tools.h>
42 options.
error =
false;
44 options.
print =
false;
51 std::string(
"This executable is an application within the ArmarX framework.\n") +
52 "==================================================================\n" +
53 " Starting an ArmarX Scenario\n" +
54 "==================================================================\n" +
55 "In order to start a Scenario pass either a path to an scx file or a Scenario name "
57 " Example command:\n\n"
59 +
" > armarx scenario command scxpath/scxname [package name] [-a application]\n\n"
64 options.
description->add_options()(
"help,h",
"Help option");
69 "What should be done: {\n \tstart, \n \tstop, \n \tkill, \n \trestart (kills by "
70 "default), \n \tlist (List all Scenario in Packages in ArmarX.DefaultPackages)\n "
71 "\tstatus (Show the status of the Scenario)\n \t generate (generate the old "
72 "local/remote icegrid xml configs)\n}");
74 value<std::string>()->default_value(
"."),
75 "Path to the scx file (default: looks in current dir)");
79 "[optional] If the packages are included in your default config as "
80 "ArmarX.DefaultPackages this can be left empty");
84 "[optional] Application out of the Scenario to execute the command with");
86 value<std::string>()->default_value(
""),
87 "[optional] Use this if you want to start an scenario "
88 "with additional commandline parameters");
90 "print",
"Print the execution commands of the CLI instead of executing them");
92 "Wait for all applications to quit before exiting");
94 positional_options_description pd;
98 pd.add(
"application", 1);
101 store(command_line_parser(argc, argv)
104 .allow_unregistered()
109 if (vm.count(
"help"))
115 if (vm.count(
"file"))
117 options.
scxPath = vm[
"file"].as<std::string>();
121 if (vm.count(
"command"))
123 options.
command = vm[
"command"].as<std::string>();
129 options.
command !=
"status" && options.
command !=
"periodic_status")
131 options.
error =
true;
135 if (vm.count(
"package"))
137 options.
packageName = vm[
"package"].as<std::string>();
140 if (vm.count(
"application"))
145 if (vm.count(
"parameters"))
147 options.
parameters = vm[
"parameters"].as<std::string>();
149 if (vm.count(
"print"))
151 options.
print =
true;
153 if (vm.count(
"wait"))
160 options.
error =
true;
170 if (!errorMessage.empty())
174 << errorMessage << std::endl;
186 std::filesystem::path boostScxPath(options.
scxPath);
188 if (std::filesystem::exists(boostScxPath))
190 if (std::filesystem::is_regular_file(boostScxPath))
192 return boostScxPath.stem().string();
194 else if (std::filesystem::is_directory(boostScxPath))
196 std::vector<std::string> all_matching_files;
198 std::filesystem::directory_iterator end_itr;
199 for (std::filesystem::directory_iterator i(boostScxPath.string()); i != end_itr;
203 if (!std::filesystem::is_regular_file(i->status()))
208 if (!(i->path().extension() ==
".scx"))
214 all_matching_files.push_back(i->path().stem().string());
217 if (all_matching_files.size() == 0)
221 else if (all_matching_files.size() == 1)
223 return all_matching_files[0];
227 std::cout <<
"Warning: found multiple scx files in this directory choosing "
228 << all_matching_files[0];
229 return all_matching_files[0];