2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
44#include "utils/Formatter.h"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
61 if (appWithPtr !=
nullptr) {
62 if (parent !=
nullptr) {
72 helpFormatter->label(
"SUBCOMMAND",
"INSTANCE");
73 helpFormatter->label(
"SUBCOMMANDS",
"INSTANCES");
74 helpFormatter->label(
"PERSISTENT",
"");
75 helpFormatter->label(
"Persistent Options",
"Options (persistent)");
76 helpFormatter->label(
"Nonpersistent Options",
"Options (nonpersistent)");
77 helpFormatter->label(
"Usage",
"\nUsage");
78 helpFormatter->label(
"bool:{true,false}",
"{true,false}");
79 helpFormatter->label(
":{standard,active,complete,required}",
"{standard,active,complete,required}");
80 helpFormatter->label(
":{standard,exact,expanded}",
"{standard,exact,expanded}");
81 helpFormatter->column_width(7);
94 "--help{exact},-h{exact}",
98 "Print help message and exit\n"
99 "* standard: display help for the last command processed\n"
100 "* exact: display help for the command directly preceding --help")
102 ->check(
CLI::IsMember({
"standard",
"exact",
"expanded"}))
103 ->trigger_on_parse()
,
108 "--help{exact},-h{exact}",
112 "Print help message and exit\n"
113 "* standard: display help for the last command processed\n"
114 "* exact: display help for the command directly preceding --help")
116 ->check(
CLI::IsMember({
"standard",
"exact"}))
117 ->trigger_on_parse()
,
127 "Show current configuration and exit")
129 ->disable_flag_override()
130 ->configurable(
false)
131 ->trigger_on_parse()
,
136 "--command-line{standard}",
137 [subCommandApp =
this->subCommandApp]([[maybe_unused]] std::int64_t count) {
140 "Print command-line\n"
141 "* standard (default): Show all non-default and required options\n"
142 "* active: Show all active options\n"
143 "* complete: Show the complete option set with default values\n"
144 "* required: Show only required options")
146 ->check(
CLI::IsMember({
"standard",
"active",
"complete",
"required"}))
147 ->trigger_on_parse()
,
184 "Read a config file",
187 ->type_name(
"configfile")
188 ->check(!
CLI::ExistingDirectory);
192 return addOption("-l,--log-file", "Log file", "logFile", defaultLogFile
, !
CLI::ExistingDirectory
);
196 return subCommandApp->set_version_flag(
"-v,--version", version,
"Framework version");
239 if (parent !=
nullptr) {
255 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands([](
const CLI::App* sc) ->
bool {
256 return sc->get_required();
263 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands([](
const CLI::App* sc) ->
bool {
264 return sc->get_required();
280 if (option->get_required() != required) {
281 option->required(required);
285 option->default_str(
"");
312 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands({})) {
313 if (sub->get_ignore_case()) {
315 sub->required(
false);
323 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands({})) {
324 if (sub->get_ignore_case()) {
353 sectionFormatter->label(
"SUBCOMMAND",
"SECTION");
354 sectionFormatter->label(
"SUBCOMMANDS",
"SECTIONS");
355 sectionFormatter->label(
"PERSISTENT",
"");
356 sectionFormatter->label(
"Persistent Options",
"Options (persistent)");
357 sectionFormatter->label(
"Nonpersistent Options",
"Options (nonpersistent)");
358 sectionFormatter->label(
"Usage",
"\nUsage");
359 sectionFormatter->label(
"bool:{true,false}",
"{true,false}");
360 sectionFormatter->label(
":{standard,active,complete,required}",
"{standard,active,complete,required}");
361 sectionFormatter->label(
":{standard,exact,expanded}",
"{standard,exact,expanded}");
362 sectionFormatter->column_width(7);
364 return sectionFormatter;
374 const std::string& description,
375 const std::string& typeName,
376 const CLI::Validator& validator)
const {
378 ->add_option(name, description)
,
385 std::function<
void(
const std::string&)>& callback,
386 const std::string& description,
387 const std::string& typeName,
388 const CLI::Validator& validator)
const {
390 ->add_option_function(name, callback, description)
,
397 const std::string& description,
398 const std::string& typeName,
399 const CLI::Validator& validator)
const {
401 ->add_flag(name, description)
,
408 const std::function<
void()>& callback,
409 const std::string& description,
410 const std::string& typeName,
411 const CLI::Validator& validator) {
415 [callback](std::int64_t) {
419 ->type_name(typeName)
422 if (opt->get_configurable()) {
423 opt->group(
subCommandApp->get_formatter()->get_label(
"Persistent Options"));
430 const std::function<
void()>& callback,
431 const std::string& description,
432 const std::string& typeName,
433 const std::string& defaultValue,
434 const CLI::Validator& validator) {
440 ->configurable(configurable)
441 ->group(
subCommandApp->get_formatter()->get_label(configurable ?
"Persistent Options" :
"Nonpersistent Options"));
447 ->type_name(typeName)
452 :
CLI::App(description, name)
const SubCommand * getPtr() const
AppWithPtr(const std::string &description, const std::string &name, SubCommand *t, bool manage)
std::string version() const
SubCommand * description(const std::string &description)
SubCommand * required(SubCommand *subCommand, bool required=true)
SubCommand * allowExtras(bool allow=true)
SubCommand * required(bool required=true, bool force=true)
CLI::Option * addOptionFunction(const std::string &name, std::function< void(const std::string &)> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
SubCommand * footer(const std::string &footer)
SubCommand * disabled(SubCommand *subCommand, bool disabled=true)
SubCommand(SubCommand *parent, std::shared_ptr< utils::AppWithPtr > appWithPtr, const std::string &group, bool final)
static CLI::App * showConfigTriggerApp
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
SubCommand * required(CLI::Option *option, bool required=true)
CLI::Option * addFlagFunction(const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator)
CLI::Option * setDefaultValue(CLI::Option *option, const ValueTypeT &value, bool clear=true) const
CLI::Option * setVersionFlag(const std::string &version) const
CLI::Option * addFlagFunction(const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
CLI::Option * commandlineOpt
SubCommand * finalCallback(const std::function< void()> &finalCallback)
AppWithPtr * subCommandApp
static std::shared_ptr< CLI::Formatter > sectionFormatter
static CLI::App * helpTriggerApp
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
CLI::Option * getOption(const std::string &name) const
static CLI::App * getHelpTriggerApp()
static CLI::App * getCommandlineTriggerApp()
CLI::Option * setConfig(const std::string &defaultConfigFile) const
CLI::Option * showConfigOpt
static std::map< std::string, std::string > aliases
std::string help(const CLI::App *helpApp, const CLI::AppFormatMode &mode) const
SubCommand * needs(SubCommand *subCommand, bool needs=true)
void parse(int argc, char *argv[])
std::string configToStr() const
static CLI::App * commandlineTriggerApp
CLI::Option * setLogFile(const std::string &defaultLogFile) const
static CLI::App * getShowConfigTriggerApp()
CLI::Option * setConfigurable(CLI::Option *option, bool configurable) const
std::string getName() const
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
CLI::Option * initialize(CLI::Option *option, const std::string &typeName, const CLI::Validator &validator, bool configurable) const
SubCommand * setRequireCallback(const std::function< void(void)> &callback)
static std::shared_ptr< CLI::HelpFormatter > makeSectionFormatter()