10 #define CLI11_EXPERIMENTAL_OPTIONAL 0
11 #include "helics/external/CLI11/CLI11.hpp"
12 #undef CLI11_EXPERIMENTAL_OPTIONAL
20 #if defined HELICS_SHARED_LIBRARY || !defined HELICS_STATIC_CORE_LIBRARY
21 # include "../application_api/timeOperations.hpp"
22 # include "../application_api/typeOperations.hpp"
28 # include "../utilities/timeStringOps.hpp"
31 using helics::core::coreTypeFromString;
32 using helics::core::to_string;
36 return gmlc::utilities::loadTimeFromString<helics::Time>(str, defUnit);
44 explicit helicsCLI11App(std::string app_description =
"",
const std::string& app_name =
""):
45 CLI::App(std::move(app_description), app_name,
nullptr)
47 set_help_flag(
"-h,-?,--help",
"Print this help message and exit");
48 set_config(
"--config-file,--config",
50 "specify base configuration file");
52 add_option_group(
"quiet")->immediate_callback()->add_flag(
"--quiet",
54 "silence most print output");
57 enum class parse_output : int {
65 bool passConfig{
true};
66 parse_output last_output{parse_output::ok};
68 template<
typename... Args>
69 parse_output helics_parse(Args&&... args) noexcept
72 parse(std::forward<Args>(args)...);
73 last_output = parse_output::ok;
74 remArgs = remaining_for_passthrough();
76 auto* opt = get_option_no_throw(
"--config");
77 if (opt !=
nullptr && opt->count() > 0) {
78 remArgs.push_back(opt->as<std::string>());
79 remArgs.emplace_back(
"--config");
83 return parse_output::ok;
85 catch (
const CLI::CallForHelp& ch) {
89 last_output = parse_output::help_call;
90 return parse_output::help_call;
92 catch (
const CLI::CallForAllHelp& ca) {
96 last_output = parse_output::help_all_call;
97 return parse_output::help_all_call;
99 catch (
const CLI::CallForVersion& cv) {
103 last_output = parse_output::version_call;
104 return parse_output::version_call;
106 catch (
const CLI::Error& ce) {
108 last_output = parse_output::parse_error;
109 return parse_output::parse_error;
112 last_output = parse_output::parse_error;
113 return parse_output::parse_error;
116 std::vector<std::string>& remainArgs() {
return remArgs; }
117 void remove_helics_specifics()
122 remove_option(get_option_no_throw(
"-v"));
123 remove_subcommand(get_option_group(
"quiet"));
125 catch (
const CLI::Error&) {
132 if (cbacks.empty()) {
134 for (
auto& cb : cbacks) {
139 cbacks.push_back(std::move(cback));
142 void addTypeOption(
bool includeEnvironmentVariable =
true)
144 auto* og = add_option_group(
"network type")->immediate_callback();
146 og->add_option_function<std::string>(
148 [
this](
const std::string& val) {
151 throw CLI::ValidationError(val +
" is NOT a recognized core type");
154 "type of the core to connect to")
155 ->default_str(
"(" +
to_string(coreType) +
")")
157 ->ignore_underscore();
158 if (includeEnvironmentVariable) {
159 typeOption->envname(
"HELICS_CORE_TYPE");
162 CoreType getCoreType()
const {
return coreType; }
167 std::vector<std::function<void()>> cbacks;
168 std::vector<std::string> remArgs;
174 namespace CLI::detail {
176 inline bool lexical_cast<helics::Time>(
const std::string& input,
helics::Time& output)
181 catch (std::invalid_argument&) {
188 constexpr
const char* type_name<helics::Time>()