52 explicit helicsCLI11App(std::string app_description =
"",
const std::string& app_name =
""):
53 CLI::App(std::move(app_description), app_name,
nullptr)
55 set_help_flag(
"-h,-?,--help",
"Print this help message and exit");
56 set_config(
"--config-file,--config",
58 "specify base configuration file");
60 add_option_group(
"quiet")->immediate_callback()->add_flag(
"--quiet",
62 "silence most print output");
65 enum class ParseOutput :
int {
71 SUCCESS_TERMINATION = 7
75 bool passConfig{
true};
76 ParseOutput last_output{ParseOutput::OK};
78 template<
typename... Args>
79 ParseOutput helics_parse(Args&&... args)
noexcept
82 parse(std::forward<Args>(args)...);
83 last_output = ParseOutput::OK;
84 remArgs = remaining_for_passthrough();
86 auto* opt = get_option_no_throw(
"--config");
87 if (opt !=
nullptr && opt->count() > 0) {
88 remArgs.push_back(opt->as<std::string>());
89 remArgs.emplace_back(
"--config");
93 catch (
const CLI::CallForHelp& ch) {
97 last_output = ParseOutput::HELP_CALL;
99 catch (
const CLI::CallForAllHelp& ca) {
103 last_output = ParseOutput::HELP_ALL_CALL;
105 catch (
const CLI::CallForVersion& cv) {
109 last_output = ParseOutput::VERSION_CALL;
111 catch (
const CLI::Success& ) {
112 last_output = ParseOutput::SUCCESS_TERMINATION;
114 catch (
const CLI::Error& ce) {
116 last_output = ParseOutput::PARSE_ERROR;
119 last_output = ParseOutput::PARSE_ERROR;
123 std::vector<std::string>& remainArgs() {
return remArgs; }
124 void remove_helics_specifics()
129 remove_option(get_option_no_throw(
"-v"));
130 remove_subcommand(get_option_group(
"quiet"));
132 catch (
const CLI::Error&) {
139 if (cbacks.empty()) {
141 for (
auto& cb : cbacks) {
146 cbacks.push_back(std::move(cback));
148 void addSystemInfoCall()
154 throw CLI::Success{};
156 "display system information details");
158 void add_config_validation()
160 auto* opt = get_option(
"--config");
161 if (opt !=
nullptr) {
162 validate_positionals();
163 opt->check([](
const std::string& fname) {
164 static const std::set<std::string> validExt = {
165 ".ini",
".toml",
".json",
".INI",
".JSON",
".TOML"};
166 auto ext = std::filesystem::path(fname).extension().string();
167 if (validExt.find(ext) == validExt.end()) {
168 return fname +
" does not have a valid extension";
170 return std::string{};
174 void addTypeOption(
bool includeEnvironmentVariable =
true)
176 auto* og = add_option_group(
"network type")->immediate_callback();
178 og->add_option_function<std::string>(
180 [
this](
const std::string& val) {
183 throw CLI::ValidationError(val +
" is NOT a recognized core type");
186 "type of the core to connect to")
187 ->default_str(
"(" +
to_string(coreType) +
")")
189 ->ignore_underscore();
190 if (includeEnvironmentVariable) {
191 typeOption->envname(
"HELICS_CORE_TYPE");
194 CoreType getCoreType()
const {
return coreType; }
199 std::vector<std::function<void()>> cbacks;
200 std::vector<std::string> remArgs;