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
62 if (appWithPtr !=
nullptr) {
63 if (parent !=
nullptr) {
83 "--help{exact},-h{exact}",
87 "Print help message and exit\n"
88 "* standard: display help for the last command processed\n"
89 "* exact: display help for the command directly preceding --help")
91 ->check(
CLI::IsMember({
"standard",
"exact"}))
101 "Show current configuration and exit")
103 ->disable_flag_override()
104 ->configurable(
false)
105 ->trigger_on_parse()
,
110 "--command-line{standard}",
111 [subCommandApp =
this->subCommandApp]([[maybe_unused]] std::int64_t count) {
114 "Print command-line\n"
115 "* standard (default): Show all non-default and required options\n"
116 "* active: Show all active options\n"
117 "* complete: Show the complete option set with default values\n"
118 "* required: Show only required options")
120 ->check(
CLI::IsMember({
"standard",
"active",
"complete",
"required"}))
121 ->trigger_on_parse()
,
169 "Read a config file",
172 ->type_name(
"configfile")
173 ->check(!
CLI::ExistingDirectory);
177 return addOption("-l,--log-file", "Log file", "logFile", defaultLogFile
, !
CLI::ExistingDirectory
);
181 return subCommandApp->set_version_flag(
"-v,--version", version,
"Framework version");
224 if (parent !=
nullptr) {
240 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands([](
const CLI::App* sc) ->
bool {
241 return sc->get_required();
248 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands([](
const CLI::App* sc) ->
bool {
249 return sc->get_required();
265 if (option->get_required() != required) {
266 option->required(required);
270 option->default_str(
"");
297 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands({})) {
298 if (sub->get_ignore_case()) {
300 sub->required(
false);
308 for (
const auto& sub : subCommand
->subCommandApp->get_subcommands({})) {
309 if (sub->get_ignore_case()) {
337 helpOpt->description(
"Print help message and exit\n"
338 "* standard: display help for the last command processed\n"
339 "* exact: display help for the command directly preceding --help\n"
340 "* expanded: display help including all descendant sections");
341 if (
auto* existing =
helpOpt->get_validator(); existing !=
nullptr) {
342 *existing = std::move(
CLI::IsMember({
"standard",
"exact",
"expanded"}));
352 sectionFormatter->label(
"SUBCOMMAND",
"SECTION");
353 sectionFormatter->label(
"SUBCOMMANDS",
"SECTIONS");
354 sectionFormatter->label(
"PERSISTENT",
"");
355 sectionFormatter->label(
"Persistent Options",
"Options (persistent)");
356 sectionFormatter->label(
"Nonpersistent Options",
"Options (nonpersistent)");
357 sectionFormatter->label(
"Usage",
"\nUsage");
358 sectionFormatter->label(
"bool:{true,false}",
"{true,false}");
359 sectionFormatter->label(
":{standard,active,complete,required}",
"{standard,active,complete,required}");
360 sectionFormatter->label(
":{standard,exact,expanded}",
"{standard,exact,expanded}");
361 sectionFormatter->column_width(7);
363 return sectionFormatter;
373 const std::string& description,
374 const std::string& typeName,
375 const CLI::Validator& validator)
const {
377 ->add_option(name, description)
,
384 const std::function<
void(
const std::string&)>& callback,
385 const std::string& description,
386 const std::string& typeName,
387 const CLI::Validator& validator)
const {
389 ->add_option_function(name, callback, description)
,
396 const std::string& description,
397 const std::string& typeName,
398 const CLI::Validator& validator)
const {
400 ->add_flag(name, description)
,
407 const std::function<
void()>& callback,
408 const std::string& description,
409 const std::string& typeName,
410 const CLI::Validator& validator)
const {
414 [callback](std::int64_t) {
418 ->type_name(typeName)
421 if (opt->get_configurable()) {
422 opt->group(
subCommandApp->get_formatter()->get_label(
"Persistent Options"));
429 const std::function<
void()>& callback,
430 const std::string& description,
431 const std::string& typeName,
432 const std::string& defaultValue,
433 const CLI::Validator& validator)
const {
439 ->configurable(configurable)
440 ->group(
subCommandApp->get_formatter()->get_label(configurable ?
"Persistent Options" :
"Nonpersistent Options"));
446 ->type_name(typeName)
451 :
CLI::App(description, name)
const SubCommand * getPtr() const
AppWithPtr(const std::string &description, const std::string &name, SubCommand *t)
CLI::Option * addFlagFunction(const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
std::string version() const
SubCommand * description(const std::string &description)
std::shared_ptr< AppWithPtr > selfAnchoredSubCommandApp
SubCommand * required(SubCommand *subCommand, bool required=true)
SubCommand * allowExtras(bool allow=true)
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) const
SubCommand * required(bool required=true, bool force=true)
SubCommand * footer(const std::string &footer)
SubCommand * disabled(SubCommand *subCommand, bool disabled=true)
void parse(int argc, char *argv[]) const
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)
SubCommand(SubCommand *parent, std::shared_ptr< utils::AppWithPtr > appWithPtr, const std::string &group, bool final=false)
CLI::Option * setDefaultValue(CLI::Option *option, const ValueTypeT &value, bool clear=true) const
std::set< SubCommand * > childSubCommands
CLI::Option * setVersionFlag(const std::string &version) const
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)
std::string configToStr() const
static CLI::App * commandlineTriggerApp
CLI::Option * setLogFile(const std::string &defaultLogFile) const
void addSubCommandApp(std::shared_ptr< utils::AppWithPtr > subCommand)
CLI::Option * addOptionFunction(const std::string &name, const std::function< void(const std::string &)> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
SubCommand * getParent() 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()