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")
92 ->check(
CLI::IsMember({
"standard",
"exact"}))
102 "Show current configuration and exit")
104 ->disable_flag_override()
105 ->configurable(
false)
106 ->trigger_on_parse()
,
111 "--command-line{standard}",
112 [subCommandApp =
this->subCommandApp]([[maybe_unused]] std::int64_t count) {
115 "Print command-line\n"
116 "* standard (default): Show all non-default and required options\n"
117 "* active: Show all active options\n"
118 "* complete: Show the complete option set with default values\n"
119 "* required: Show only required options")
122 ->check(
CLI::IsMember({
"standard",
"active",
"complete",
"required"}))
123 ->trigger_on_parse()
,
198 const bool previouslyRequired =
subCommandApp->get_required();
199 const bool countedRequired =
subCommandApp->get_ignore_case();
203 const bool effectiveRequired =
requiredForced ?
false : countedRequired;
204 if (previouslyRequired != effectiveRequired) {
218 const bool previousEffectiveRequired =
subCommandApp->get_required();
222 const bool effectiveRequired =
requiredForced ?
false : countedRequired;
229 if (
hasParent() && previousEffectiveRequired != effectiveRequired) {
240 if (option->get_required() != required) {
241 option->required(required);
245 option->default_str(
"");
284 helpOpt->description(
"Print help message and exit\n"
285 "* standard: display help for the last command processed\n"
286 "* exact: display help for the command directly preceding --help\n"
287 "* expanded: display help including all descendant sections");
288 if (
auto* existing =
helpOpt->get_validator(); existing !=
nullptr) {
289 *existing = std::move(
CLI::IsMember({
"standard",
"exact",
"expanded"}));
301 "Read a config file",
304 ->type_name(
"configfile")
305 ->check(!
CLI::ExistingDirectory);
309 return addOption("-l,--log-file", "Log file", "logFile", defaultLogFile
, !
CLI::ExistingDirectory
);
313 return subCommandApp->set_version_flag(
"-v,--version", version,
"Framework version");
317 const std::string& description,
318 const std::string& typeName,
319 const CLI::Validator& validator)
const {
321 ->add_option(name, description)
,
328 const std::function<
void(
const std::string&)>& callback,
329 const std::string& description,
330 const std::string& typeName,
331 const CLI::Validator& validator)
const {
333 ->add_option_function(name, callback, description)
,
340 const std::string& description,
341 const std::string& typeName,
342 const CLI::Validator& validator)
const {
344 ->add_flag(name, description)
,
351 const std::function<
void()>& callback,
352 const std::string& description,
353 const std::string& typeName,
354 const CLI::Validator& validator)
const {
358 [callback](std::int64_t) {
362 ->type_name(typeName)
365 if (opt->get_configurable()) {
366 opt->group(
subCommandApp->get_formatter()->get_label(
"Persistent Options"));
373 const std::function<
void()>& callback,
374 const std::string& description,
375 const std::string& typeName,
376 const std::string& defaultValue,
377 const CLI::Validator& validator)
const {
387 ->configurable(configurable)
388 ->group(
subCommandApp->get_formatter()->get_label(configurable ?
"Persistent Options" :
"Nonpersistent Options"));
406 ->type_name(typeName)
411 :
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 * required(bool required=true)
SubCommand * description(const std::string &description)
std::shared_ptr< AppWithPtr > selfAnchoredSubCommandApp
SubCommand * forceUnrequired(bool unrequired=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 * footer(const std::string &footer)
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 * addLogFileFlag(const std::string &defaultLogFile) const
CLI::Option * setDefaultValue(CLI::Option *option, const ValueTypeT &value, bool clear=true) const
std::set< SubCommand * > childSubCommands
CLI::Option * addVersionFlag(const std::string &version) const
CLI::Option * commandlineOpt
SubCommand * finalCallback(const std::function< void()> &finalCallback)
AppWithPtr * subCommandApp
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 * 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
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
CLI::Option * addConfigFlag(const std::string &defaultConfigFile) const
SubCommand * setRequireCallback(const std::function< void(void)> &callback)