10 #define CLI11_EXPERIMENTAL_OPTIONAL 0
11 #define CLI11_HAS_FILESYSTEM 1
12 #include "helics/external/CLI11/CLI11.hpp"
13 #undef CLI11_EXPERIMENTAL_OPTIONAL
21 #if defined HELICS_SHARED_LIBRARY || !defined HELICS_STATIC_CORE_LIBRARY
22 # include "../application_api/timeOperations.hpp"
23 # include "../application_api/typeOperations.hpp"
31 # include "../utilities/timeStringOps.hpp"
34 using helics::core::coreTypeFromString;
36 using helics::core::to_string;
40 return gmlc::utilities::loadTimeFromString<helics::Time>(str, defUnit);
48 explicit helicsCLI11App(std::string app_description =
"",
const std::string& app_name =
""):
49 CLI::App(std::move(app_description), app_name,
nullptr)
51 set_help_flag(
"-h,-?,--help",
"Print this help message and exit");
52 set_config(
"--config-file,--config",
54 "specify base configuration file");
56 add_option_group(
"quiet")->immediate_callback()->add_flag(
"--quiet",
58 "silence most print output");
61 enum class ParseOutput : int {
67 SUCCESS_TERMINATION = 7
71 bool passConfig{
true};
72 ParseOutput last_output{ParseOutput::OK};
74 template<
typename... Args>
75 ParseOutput helics_parse(Args&&... args) noexcept
78 parse(std::forward<Args>(args)...);
79 last_output = ParseOutput::OK;
80 remArgs = remaining_for_passthrough();
82 auto* opt = get_option_no_throw(
"--config");
83 if (opt !=
nullptr && opt->count() > 0) {
84 remArgs.push_back(opt->as<std::string>());
85 remArgs.emplace_back(
"--config");
89 catch (
const CLI::CallForHelp& ch) {
93 last_output = ParseOutput::HELP_CALL;
95 catch (
const CLI::CallForAllHelp& ca) {
99 last_output = ParseOutput::HELP_ALL_CALL;
101 catch (
const CLI::CallForVersion& cv) {
105 last_output = ParseOutput::VERSION_CALL;
107 catch (
const CLI::Success& ) {
108 last_output = ParseOutput::SUCCESS_TERMINATION;
110 catch (
const CLI::Error& ce) {
112 last_output = ParseOutput::PARSE_ERROR;
115 last_output = ParseOutput::PARSE_ERROR;
119 std::vector<std::string>& remainArgs() {
return remArgs; }
120 void remove_helics_specifics()
125 remove_option(get_option_no_throw(
"-v"));
126 remove_subcommand(get_option_group(
"quiet"));
128 catch (
const CLI::Error&) {
135 if (cbacks.empty()) {
137 for (
auto& cb : cbacks) {
142 cbacks.push_back(std::move(cback));
144 void addSystemInfoCall()
150 throw CLI::Success{};
152 "display system information details");
155 void addTypeOption(
bool includeEnvironmentVariable =
true)
157 auto* og = add_option_group(
"network type")->immediate_callback();
159 og->add_option_function<std::string>(
161 [
this](
const std::string& val) {
164 throw CLI::ValidationError(val +
" is NOT a recognized core type");
167 "type of the core to connect to")
168 ->default_str(
"(" +
to_string(coreType) +
")")
170 ->ignore_underscore();
171 if (includeEnvironmentVariable) {
172 typeOption->envname(
"HELICS_CORE_TYPE");
175 CoreType getCoreType()
const {
return coreType; }
180 std::vector<std::function<void()>> cbacks;
181 std::vector<std::string> remArgs;
187 namespace CLI::detail {
189 inline bool lexical_cast<helics::Time>(
const std::string& input,
helics::Time& output)
194 catch (std::invalid_argument&) {
201 constexpr
const char* type_name<helics::Time>()
Definition: helicsCLI11.hpp:46
void add_callback(std::function< void()> cback)
Definition: helicsCLI11.hpp:133
void setDefaultCoreType(CoreType type)
Definition: helicsCLI11.hpp:177
std::string systemInfo()
Definition: helicsVersion.cpp:195
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
CoreType
Definition: CoreTypes.hpp:46
@ DEFAULT
ZMQ if available or UDP.
CoreType coreTypeFromString(std::string_view type) noexcept
Definition: typeOperations.cpp:18
std::string to_string(CoreType type)
Definition: typeOperations.cpp:13
Time loadTimeFromString(std::string_view timeString)
Definition: timeOperations.cpp:21
constexpr auto versionString
Definition: helicsVersion.hpp:18
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
std::string systemInfo()
Definition: typeOperations.cpp:28