10 #define CLI11_EXPERIMENTAL_OPTIONAL 0
11 #include "helics/external/CLI11/CLI11.hpp"
16 #undef CLI11_EXPERIMENTAL_OPTIONAL
19 #if defined HELICS_SHARED_LIBRARY || !defined HELICS_STATIC_CORE_LIBRARY
20 # include "../application_api/timeOperations.hpp"
21 # include "../application_api/typeOperations.hpp"
27 # include "../utilities/timeStringOps.hpp"
30 using helics::core::coreTypeFromString;
31 using helics::core::to_string;
35 return gmlc::utilities::loadTimeFromString<helics::Time>(str, defUnit);
43 explicit helicsCLI11App(std::string app_description =
"",
const std::string& app_name =
""):
44 CLI::App(std::move(app_description), app_name,
nullptr)
46 set_help_flag(
"-h,-?,--help",
"Print this help message and exit");
47 set_config(
"--config-file,--config",
49 "specify base configuration file");
51 add_option_group(
"quiet")->immediate_callback()->add_flag(
"--quiet",
53 "silence most print output");
56 enum class parse_output : int {
64 bool passConfig{
true};
65 parse_output last_output{parse_output::ok};
67 template<
typename... Args>
68 parse_output helics_parse(Args&&... args) noexcept
71 parse(std::forward<Args>(args)...);
72 last_output = parse_output::ok;
73 remArgs = remaining_for_passthrough();
75 auto* opt = get_option_no_throw(
"--config");
76 if (opt !=
nullptr && opt->count() > 0) {
77 remArgs.push_back(opt->as<std::string>());
78 remArgs.emplace_back(
"--config");
82 return parse_output::ok;
84 catch (
const CLI::CallForHelp& ch) {
88 last_output = parse_output::help_call;
89 return parse_output::help_call;
91 catch (
const CLI::CallForAllHelp& ca) {
95 last_output = parse_output::help_all_call;
96 return parse_output::help_all_call;
98 catch (
const CLI::CallForVersion& cv) {
102 last_output = parse_output::version_call;
103 return parse_output::version_call;
105 catch (
const CLI::Error& ce) {
107 last_output = parse_output::parse_error;
108 return parse_output::parse_error;
111 last_output = parse_output::parse_error;
112 return parse_output::parse_error;
115 std::vector<std::string>& remainArgs() {
return remArgs; }
116 void remove_helics_specifics()
121 remove_option(get_option_no_throw(
"-v"));
122 remove_subcommand(get_option_group(
"quiet"));
124 catch (
const CLI::Error&) {
131 if (cbacks.empty()) {
133 for (
auto& cb : cbacks) {
138 cbacks.push_back(std::move(cback));
141 void addTypeOption(
bool includeEnvironmentVariable =
true)
143 auto* og = add_option_group(
"network type")->immediate_callback();
145 og->add_option_function<std::string>(
146 "--coretype,-t,--type,--core",
147 [
this](
const std::string& val) {
150 throw CLI::ValidationError(val +
" is NOT a recognized core type");
153 "type of the core to connect to")
154 ->default_str(
"(" +
to_string(coreType) +
")");
155 if (includeEnvironmentVariable) {
156 typeOption->envname(
"HELICS_CORE_TYPE");
159 core_type getCoreType()
const {
return coreType; }
164 std::vector<std::function<void()>> cbacks;
165 std::vector<std::string> remArgs;
174 inline bool lexical_cast<helics::Time>(
const std::string& input,
helics::Time& output)
179 catch (std::invalid_argument&) {
186 constexpr
const char* type_name<helics::Time>()