SNode.C
Loading...
Searching...
No Matches
utils::SubCommand Class Reference

#include <SubCommand.h>

Inheritance diagram for utils::SubCommand:
Collaboration diagram for utils::SubCommand:

Public Member Functions

 SubCommand (const SubCommand &)=delete
 SubCommand (SubCommand &&)=delete
SubCommandoperator= (const SubCommand &)=delete
SubCommandoperator= (SubCommand &&)=delete
virtual ~SubCommand ()
std::string getName () const
std::string version () const
CLI::Option * setConfig (const std::string &defaultConfigFile) const
CLI::Option * setLogFile (const std::string &defaultLogFile) const
CLI::Option * setVersionFlag (const std::string &version) const
bool hasParent () const
SubCommandgetParent () const
SubCommandallowExtras (bool allow=true)
SubCommandrequired (bool required=true, bool force=true)
SubCommandrequired (SubCommand *subCommand, bool required=true)
SubCommandrequired (CLI::Option *option, bool required=true)
bool getRequired () const
SubCommandneeds (SubCommand *subCommand, bool needs=true)
SubCommanddisabled (SubCommand *subCommand, bool disabled=true)
SubCommandsetRequireCallback (const std::function< void(void)> &callback)
SubCommandfinalCallback (const std::function< void()> &finalCallback)
std::string configToStr () const
std::string help (const CLI::App *helpApp, const CLI::AppFormatMode &mode) const
void addSubCommandApp (std::shared_ptr< utils::AppWithPtr > subCommand)
template<typename NewSubCommand, typename... Args>
NewSubCommand * newSubCommand (Args &&... args)
template<typename RequestedSubCommand>
RequestedSubCommand * getSubCommand ()
template<typename RequestedSubCommand>
RequestedSubCommand * getSubCommand () const
CLI::Option * getOption (const std::string &name) const
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addOptionVariable (const std::string &name, ValueTypeT &variable, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator) const
template<typename ValueTypeT>
CLI::Option * addOptionVariable (const std::string &name, ValueTypeT &variable, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator) const
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
template<typename ValueTypeT>
CLI::Option * addOptionFunction (const std::string &name, const std::function< void(const std::string &)> &callback, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
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
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

Protected Member Functions

 SubCommand (SubCommand *parent, std::shared_ptr< utils::AppWithPtr > appWithPtr, const std::string &group, bool final=false)
template<typename ConcretSubCommand>
 SubCommand (SubCommand *parent, ConcretSubCommand *concretSubCommand, const std::string &group, bool final=false)
void parse (int argc, char *argv[]) const
SubCommanddescription (const std::string &description)
SubCommandfooter (const std::string &footer)
void removeSubCommand ()
template<typename ValueTypeT>
CLI::Option * setDefaultValue (CLI::Option *option, const ValueTypeT &value, bool clear=true) const
CLI::Option * setConfigurable (CLI::Option *option, bool configurable) const

Static Protected Member Functions

static CLI::App * getHelpTriggerApp ()
static CLI::App * getShowConfigTriggerApp ()
static CLI::App * getCommandlineTriggerApp ()

Protected Attributes

CLI::Option * helpOpt = nullptr

Static Protected Attributes

static std::shared_ptr< CLI::Formatter > sectionFormatter = makeSectionFormatter()
static std::map< std::string, std::string > aliases
static CLI::App * helpTriggerApp = nullptr
static CLI::App * showConfigTriggerApp = nullptr
static CLI::App * commandlineTriggerApp = nullptr

Private Member Functions

CLI::Option * initialize (CLI::Option *option, const std::string &typeName, const CLI::Validator &validator, bool configurable) const

Private Attributes

AppWithPtrsubCommandApp
std::string name
SubCommandparent
std::shared_ptr< AppWithPtrselfAnchoredSubCommandApp
std::set< SubCommand * > childSubCommands
bool final
CLI::Option * showConfigOpt = nullptr
CLI::Option * commandlineOpt = nullptr
int requiredCount = 0

Detailed Description

Definition at line 97 of file SubCommand.h.

Constructor & Destructor Documentation

◆ SubCommand() [1/4]

utils::SubCommand::SubCommand ( SubCommand * parent,
std::shared_ptr< utils::AppWithPtr > appWithPtr,
const std::string & group,
bool final = false )
protected

Definition at line 57 of file SubCommand.cpp.

58 : subCommandApp(appWithPtr.get())
59 , name(subCommandApp != nullptr ? subCommandApp->get_name() : "<NOAPP>")
60 , parent(parent)
61 , final(final) {
62 if (appWithPtr != nullptr) {
63 if (parent != nullptr) {
64 parent->addSubCommandApp(appWithPtr);
65 } else {
66 selfAnchoredSubCommandApp = std::move(appWithPtr);
67 }
68
69 subCommandApp->group(group);
70 subCommandApp->configurable(false);
71 subCommandApp->fallthrough();
72
73 static const std::shared_ptr<CLI::HelpFormatter> helpFormatter = std::make_shared<CLI::HelpFormatter>();
74 subCommandApp->formatter(helpFormatter);
75
76 static const std::shared_ptr<CLI::Config> configFormatter = std::make_shared<CLI::ConfigFormatter>();
77 subCommandApp->config_formatter(configFormatter);
78
79 subCommandApp->option_defaults()->take_last()->group(subCommandApp->get_formatter()->get_label("Nonpersistent Options"));
80
82 ->set_help_flag(
83 "--help{exact},-h{exact}",
84 [subCommandApp = this->subCommandApp](std::size_t) {
86 },
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")
90 ->take_first()
91 ->check(CLI::IsMember({"standard", "exact"}))
92 ->trigger_on_parse(),
93 false);
94
96 ->add_flag_function(
97 "-s,--show-config",
98 [subCommandApp = this->subCommandApp](std::size_t) {
100 },
101 "Show current configuration and exit")
102 ->take_first()
103 ->disable_flag_override()
104 ->configurable(false)
105 ->trigger_on_parse(),
106 false);
107
109 ->add_flag_function(
110 "--command-line{standard}",
111 [subCommandApp = this->subCommandApp]([[maybe_unused]] std::int64_t count) {
113 },
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")
119 ->take_first()
120 ->check(CLI::IsMember({"standard", "active", "complete", "required"}))
121 ->trigger_on_parse(),
122 false);
123 }
124 }
std::shared_ptr< AppWithPtr > selfAnchoredSubCommandApp
Definition SubCommand.h:255
static CLI::App * showConfigTriggerApp
Definition SubCommand.h:245
CLI::Option * commandlineOpt
Definition SubCommand.h:265
CLI::Option * helpOpt
Definition SubCommand.h:261
AppWithPtr * subCommandApp
Definition SubCommand.h:251
SubCommand * parent
Definition SubCommand.h:253
static CLI::App * helpTriggerApp
Definition SubCommand.h:244
std::string name
Definition SubCommand.h:252
CLI::Option * showConfigOpt
Definition SubCommand.h:264
static CLI::App * commandlineTriggerApp
Definition SubCommand.h:246
CLI::Option * setConfigurable(CLI::Option *option, bool configurable) const

References addSubCommandApp(), commandlineOpt, commandlineTriggerApp, final, helpOpt, helpTriggerApp, name, parent, selfAnchoredSubCommandApp, setConfigurable(), showConfigOpt, showConfigTriggerApp, and subCommandApp.

Referenced by net::config::ConfigInstance::ConfigInstance(), and utils::ConfigRoot::ConfigRoot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SubCommand() [2/4]

template<typename ConcretSubCommand>
utils::SubCommand::SubCommand ( SubCommand * parent,
ConcretSubCommand * concretSubCommand,
const std::string & group,
bool final = false )
inlineprotected

Definition at line 271 of file SubCommand.h.

273 std::make_shared<utils::AppWithPtr>(
274 std::string(ConcretSubCommand::DESCRIPTION), std::string(ConcretSubCommand::NAME), concretSubCommand),
275 group,
276 final) {
277 }
SubCommand(SubCommand *parent, std::shared_ptr< utils::AppWithPtr > appWithPtr, const std::string &group, bool final=false)

Referenced by web::http::client::ConfigHTTP::ConfigHTTP(), and subcommand::ConfigWWW::ConfigWWW().

Here is the caller graph for this function:

◆ SubCommand() [3/4]

utils::SubCommand::SubCommand ( const SubCommand & )
delete

◆ SubCommand() [4/4]

utils::SubCommand::SubCommand ( SubCommand && )
delete

◆ ~SubCommand()

utils::SubCommand::~SubCommand ( )
virtual

Definition at line 126 of file SubCommand.cpp.

126 {
127 }

Member Function Documentation

◆ addFlag() [1/2]

CLI::Option * utils::SubCommand::addFlag ( const std::string & name,
const std::string & description,
const std::string & typeName,
const CLI::Validator & validator ) const

Definition at line 395 of file SubCommand.cpp.

398 {
399 return initialize(subCommandApp //
400 ->add_flag(name, description),
401 typeName,
402 validator,
403 !subCommandApp->get_disabled());
404 }
SubCommand * description(const std::string &description)
CLI::Option * initialize(CLI::Option *option, const std::string &typeName, const CLI::Validator &validator, bool configurable) const

References initialize(), and subCommandApp.

Referenced by addFlag(), and utils::ConfigRoot::addRootOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addFlag() [2/2]

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::addFlag ( const std::string & name,
const std::string & description,
const std::string & typeName,
ValueTypeT defaultValue,
const CLI::Validator & validator ) const

Definition at line 358 of file SubCommand.h.

362 {
363 return setDefaultValue(addFlag(name, description, typeName, additionalValidator), defaultValue);
364 }
CLI::Option * setDefaultValue(CLI::Option *option, const ValueTypeT &value, bool clear=true) const
Definition SubCommand.h:367
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const

References addFlag().

Referenced by utils::ConfigRoot::addRootOptions(), web::http::client::ConfigHTTP::ConfigHTTP(), net::config::ConfigPhysicalSocket::ConfigPhysicalSocket(), net::config::ConfigTls::ConfigTls(), and net::config::ConfigTlsServer::ConfigTlsServer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addFlagFunction() [1/2]

CLI::Option * utils::SubCommand::addFlagFunction ( const std::string & name,
const std::function< void()> & callback,
const std::string & description,
const std::string & typeName,
const CLI::Validator & validator ) const

Definition at line 406 of file SubCommand.cpp.

410 {
411 CLI::Option* opt = subCommandApp //
412 ->add_flag_function(
413 name,
414 [callback](std::int64_t) {
415 callback();
416 },
418 ->type_name(typeName)
419 ->check(validator)
420 ->take_last();
421 if (opt->get_configurable()) {
422 opt->group(subCommandApp->get_formatter()->get_label("Persistent Options"));
423 }
424
425 return opt;
426 }

References subCommandApp.

Referenced by addFlagFunction().

Here is the caller graph for this function:

◆ addFlagFunction() [2/2]

CLI::Option * utils::SubCommand::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

Definition at line 428 of file SubCommand.cpp.

433 {
434 return setDefaultValue(addFlagFunction(name, callback, description, typeName, validator), defaultValue);
435 }
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

References addFlagFunction(), and setDefaultValue().

Referenced by utils::ConfigRoot::addRootOptions(), net::config::ConfigPhysicalSocket::addSocketOption(), net::config::ConfigInstance::ConfigInstance(), and net::config::ConfigPhysicalSocketClient::ConfigPhysicalSocketClient().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOption() [1/2]

CLI::Option * utils::SubCommand::addOption ( const std::string & name,
const std::string & description,
const std::string & typeName,
const CLI::Validator & validator ) const

Definition at line 372 of file SubCommand.cpp.

375 {
376 return initialize(subCommandApp //
377 ->add_option(name, description),
378 typeName,
379 validator,
380 !subCommandApp->get_disabled());
381 }

References initialize(), and subCommandApp.

Referenced by addOption(), utils::ConfigRoot::addRootOptions(), web::http::client::ConfigHTTP::ConfigHTTP(), net::config::ConfigTls::ConfigTls(), net::config::ConfigTlsClient::ConfigTlsClient(), and subcommand::ConfigWWW::ConfigWWW().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOption() [2/2]

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::addOption ( const std::string & name,
const std::string & description,
const std::string & typeName,
ValueTypeT defaultValue,
const CLI::Validator & validator ) const

Definition at line 319 of file SubCommand.h.

323 {
324 return setDefaultValue(addOption(name, description, typeName, additionalValidator), defaultValue);
325 }
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const

References addOption().

Referenced by utils::ConfigRoot::addRootOptions(), net::config::ConfigPhysicalSocket::ConfigPhysicalSocket(), net::config::ConfigTls::ConfigTls(), and setLogFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOptionFunction() [1/2]

CLI::Option * utils::SubCommand::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

Definition at line 383 of file SubCommand.cpp.

387 {
388 return initialize(subCommandApp //
389 ->add_option_function(name, callback, description),
390 typeName,
391 validator,
392 !subCommandApp->get_disabled());
393 }

References initialize(), and subCommandApp.

Referenced by addOptionFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOptionFunction() [2/2]

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::addOptionFunction ( const std::string & name,
const std::function< void(const std::string &)> & callback,
const std::string & description,
const std::string & typeName,
ValueTypeT defaultValue,
const CLI::Validator & validator ) const

Definition at line 348 of file SubCommand.h.

353 {
354 return setDefaultValue(addOptionFunction(name, callback, description, typeName, validator), defaultValue);
355 }
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

References addOptionFunction().

Here is the call graph for this function:

◆ addOptionVariable() [1/2]

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::addOptionVariable ( const std::string & name,
ValueTypeT & variable,
const std::string & description,
const std::string & typeName,
const CLI::Validator & additionalValidator ) const

Definition at line 328 of file SubCommand.h.

332 {
333 return initialize(
334 subCommandApp->add_option(name, variable, description), typeName, additionalValidator, !subCommandApp->get_disabled());
335 }

References initialize(), and subCommandApp.

Referenced by net::config::ConfigTlsServer::ConfigTlsServer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOptionVariable() [2/2]

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::addOptionVariable ( const std::string & name,
ValueTypeT & variable,
const std::string & description,
const std::string & typeName,
ValueTypeT defaultValue,
const CLI::Validator & additionalValidator ) const

Definition at line 338 of file SubCommand.h.

343 {
344 return setDefaultValue(addOptionVariable(name, variable, description, typeName, additionalValidator), defaultValue);
345 }
CLI::Option * addOptionVariable(const std::string &name, ValueTypeT &variable, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator) const
Definition SubCommand.h:328

◆ addSubCommandApp()

void utils::SubCommand::addSubCommandApp ( std::shared_ptr< utils::AppWithPtr > subCommand)

Definition at line 335 of file SubCommand.cpp.

335 {
336 if (subCommandApp->get_subcommands({}).empty()) {
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"})); // replace, do not append
343 }
344 }
345
346 subCommandApp->add_subcommand(subCommand);
347 }

References helpOpt, and subCommandApp.

Referenced by SubCommand().

Here is the caller graph for this function:

◆ allowExtras()

SubCommand * utils::SubCommand::allowExtras ( bool allow = true)

Definition at line 198 of file SubCommand.cpp.

198 {
199 subCommandApp->allow_extras(allow);
200
201 return this;
202 }

References subCommandApp.

Referenced by utils::ConfigRoot::parse1().

Here is the caller graph for this function:

◆ configToStr()

std::string utils::SubCommand::configToStr ( ) const

Definition at line 327 of file SubCommand.cpp.

327 {
328 return subCommandApp->config_to_str(true, true);
329 }

References subCommandApp.

Referenced by utils::doWriteConfig().

Here is the caller graph for this function:

◆ description()

SubCommand * utils::SubCommand::description ( const std::string & description)
protected

Definition at line 141 of file SubCommand.cpp.

141 {
142 subCommandApp->description(description);
143
144 return this;
145 }

References subCommandApp.

Referenced by utils::ConfigRoot::addRootOptions(), and net::config::ConfigSection::ConfigSection().

Here is the caller graph for this function:

◆ disabled()

SubCommand * utils::SubCommand::disabled ( SubCommand * subCommand,
bool disabled = true )

Definition at line 291 of file SubCommand.cpp.

291 {
292 if (disabled) {
293 if (subCommand->subCommandApp->get_ignore_case()) {
294 needs(subCommand, false);
295 }
296
297 for (const auto& sub : subCommand->subCommandApp->get_subcommands({})) {
298 if (sub->get_ignore_case()) {
299 subCommand->subCommandApp->remove_needs(sub);
300 sub->required(false);
301 }
302 }
303 } else {
304 if (subCommand->subCommandApp->get_ignore_case()) {
305 needs(subCommand);
306 }
307
308 for (const auto& sub : subCommand->subCommandApp->get_subcommands({})) {
309 if (sub->get_ignore_case()) {
310 subCommand->subCommandApp->needs(sub);
311 sub->required();
312 }
313 }
314 }
315
316 subCommand->subCommandApp->required(disabled ? false : subCommand->subCommandApp->get_ignore_case());
317
318 return this;
319 }
SubCommand * disabled(SubCommand *subCommand, bool disabled=true)
SubCommand * needs(SubCommand *subCommand, bool needs=true)

References needs(), and subCommandApp.

Referenced by net::config::ConfigInstance::ConfigInstance(), and net::config::ConfigInstance::setDisabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalCallback()

SubCommand * utils::SubCommand::finalCallback ( const std::function< void()> & finalCallback)

Definition at line 321 of file SubCommand.cpp.

321 {
322 subCommandApp->final_callback(finalCallback);
323
324 return this;
325 }
SubCommand * finalCallback(const std::function< void()> &finalCallback)

References subCommandApp.

Referenced by utils::ConfigRoot::bootstrap(), and net::config::ConfigTlsServer::ConfigTlsServer().

Here is the caller graph for this function:

◆ footer()

SubCommand * utils::SubCommand::footer ( const std::string & footer)
protected

Definition at line 147 of file SubCommand.cpp.

147 {
148 subCommandApp->footer(footer);
149
150 return this;
151 }
SubCommand * footer(const std::string &footer)

References subCommandApp.

Referenced by utils::ConfigRoot::addRootOptions().

Here is the caller graph for this function:

◆ getCommandlineTriggerApp()

CLI::App * utils::SubCommand::getCommandlineTriggerApp ( )
staticprotected

Definition at line 204 of file SubCommand.cpp.

204 {
206 }

References commandlineTriggerApp.

Referenced by net::config::ConfigInstance::getCommandlineTriggerApp().

Here is the caller graph for this function:

◆ getHelpTriggerApp()

CLI::App * utils::SubCommand::getHelpTriggerApp ( )
staticprotected

Definition at line 212 of file SubCommand.cpp.

212 {
213 return helpTriggerApp;
214 }

References helpTriggerApp.

Referenced by net::config::ConfigInstance::getHelpTriggerApp().

Here is the caller graph for this function:

◆ getName()

std::string utils::SubCommand::getName ( ) const

Definition at line 129 of file SubCommand.cpp.

129 {
130 return name;
131 }

References name.

Referenced by net::config::ConfigTlsServer::ConfigTlsServer().

Here is the caller graph for this function:

◆ getOption()

CLI::Option * utils::SubCommand::getOption ( const std::string & name) const

Definition at line 368 of file SubCommand.cpp.

368 {
369 return subCommandApp->get_option_no_throw(name);
370 }

References subCommandApp.

Referenced by net::config::ConfigPhysicalSocket::addSocketOption(), utils::doWriteConfig(), utils::getHelp(), and utils::ConfigRoot::parse2().

Here is the caller graph for this function:

◆ getParent()

SubCommand * utils::SubCommand::getParent ( ) const

Definition at line 188 of file SubCommand.cpp.

188 {
189 return parent;
190 }

References parent.

Referenced by net::config::ConfigInstance::ConfigInstance(), net::config::ConfigTlsServer::ConfigTlsServer(), required(), and net::config::ConfigInstance::setDisabled().

Here is the caller graph for this function:

◆ getRequired()

bool utils::SubCommand::getRequired ( ) const
inline

Definition at line 138 of file SubCommand.h.

138 {
139 return subCommandApp->get_required();
140 }

References subCommandApp.

◆ getShowConfigTriggerApp()

CLI::App * utils::SubCommand::getShowConfigTriggerApp ( )
staticprotected

Definition at line 208 of file SubCommand.cpp.

208 {
210 }

References showConfigTriggerApp.

Referenced by net::config::ConfigInstance::getShowConfigTriggerApp().

Here is the caller graph for this function:

◆ getSubCommand() [1/2]

template<typename RequestedSubCommand>
RequestedSubCommand * utils::SubCommand::getSubCommand ( )

Definition at line 301 of file SubCommand.h.

301 {
302 auto* appWithPtr = subCommandApp->get_subcommand_no_throw(std::string(RequestedSubCommand::NAME));
303
304 AppWithPtr* subCommandApp = dynamic_cast<utils::AppWithPtr*>(appWithPtr);
305
306 return subCommandApp != nullptr ? dynamic_cast<RequestedSubCommand*>(subCommandApp->getPtr()) : nullptr;
307 }

References utils::AppWithPtr::getPtr(), and subCommandApp.

Referenced by web::http::client::SocketContextFactory::create(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubCommand() [2/2]

template<typename RequestedSubCommand>
RequestedSubCommand * utils::SubCommand::getSubCommand ( ) const

Definition at line 310 of file SubCommand.h.

310 {
311 auto* appWithPtr = subCommandApp->get_subcommand_no_throw(std::string(RequestedSubCommand::NAME));
312
313 AppWithPtr* subCommandApp = dynamic_cast<utils::AppWithPtr*>(appWithPtr);
314
315 return subCommandApp != nullptr ? dynamic_cast<RequestedSubCommand*>(subCommandApp->getPtr()) : nullptr;
316 }

References utils::AppWithPtr::getPtr(), and subCommandApp.

Here is the call graph for this function:

◆ hasParent()

bool utils::SubCommand::hasParent ( ) const

Definition at line 184 of file SubCommand.cpp.

184 {
185 return subCommandApp->get_parent() != nullptr;
186 }

References subCommandApp.

◆ help()

std::string utils::SubCommand::help ( const CLI::App * helpApp,
const CLI::AppFormatMode & mode ) const

Definition at line 331 of file SubCommand.cpp.

331 {
332 return subCommandApp->help(helpApp, "", mode);
333 }

References subCommandApp.

Referenced by utils::getHelp().

Here is the caller graph for this function:

◆ initialize()

CLI::Option * utils::SubCommand::initialize ( CLI::Option * option,
const std::string & typeName,
const CLI::Validator & validator,
bool configurable ) const
private

Definition at line 444 of file SubCommand.cpp.

444 {
445 return setConfigurable(option, configurable) //
446 ->type_name(typeName)
447 ->check(validator);
448 }

References setConfigurable().

Referenced by addFlag(), addOption(), addOptionFunction(), and addOptionVariable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ needs()

SubCommand * utils::SubCommand::needs ( SubCommand * subCommand,
bool needs = true )

Definition at line 281 of file SubCommand.cpp.

281 {
282 if (needs) {
283 subCommandApp->needs(subCommand->subCommandApp);
284 } else {
285 subCommandApp->remove_needs(subCommand->subCommandApp);
286 }
287
288 return this;
289 }

References subCommandApp.

Referenced by disabled(), required(), and required().

Here is the caller graph for this function:

◆ newSubCommand()

template<typename NewSubCommand, typename... Args>
NewSubCommand * utils::SubCommand::newSubCommand ( Args &&... args)

Definition at line 280 of file SubCommand.h.

280 {
281 NewSubCommand* newSubCommand = nullptr;
282
283 if (!final) {
284 /*
285 helpOpt->description("Print help message and exit\n"
286 "* standard: display help for the last command processed\n"
287 "* exact: display help for the command directly preceding --help\n"
288 "* expanded: display help including all descendant sections");
289 if (auto* existing = helpOpt->get_validator(); existing != nullptr) {
290 *existing = std::move(CLI::IsMember({"standard", "exact", "expanded"})); // replace, do not append
291 }
292 */
294 dynamic_cast<NewSubCommand*>(*childSubCommands.insert(new NewSubCommand(this, std::forward<Args>(args)...)).first);
295 }
296
297 return newSubCommand;
298 }
NewSubCommand * newSubCommand(Args &&... args)
Definition SubCommand.h:280
std::set< SubCommand * > childSubCommands
Definition SubCommand.h:256

References final.

Referenced by main().

Here is the caller graph for this function:

◆ operator=() [1/2]

SubCommand & utils::SubCommand::operator= ( const SubCommand & )
delete

◆ operator=() [2/2]

SubCommand & utils::SubCommand::operator= ( SubCommand && )
delete

◆ parse()

void utils::SubCommand::parse ( int argc,
char * argv[] ) const
protected

Definition at line 137 of file SubCommand.cpp.

137 {
138 subCommandApp->parse(argc, argv);
139 }

References subCommandApp.

Referenced by utils::Config::parse(), and utils::ConfigRoot::parse2().

Here is the caller graph for this function:

◆ removeSubCommand()

void utils::SubCommand::removeSubCommand ( )
protected

Definition at line 153 of file SubCommand.cpp.

153 {
154 for (const SubCommand* child : childSubCommands) {
155 delete child;
156 }
157 childSubCommands.clear();
158
159 if (parent != nullptr) {
160 parent->subCommandApp->remove_subcommand(subCommandApp);
161 }
162 }

References childSubCommands, parent, and subCommandApp.

Referenced by utils::ConfigRoot::terminate(), and net::config::ConfigInstance::~ConfigInstance().

Here is the caller graph for this function:

◆ required() [1/3]

SubCommand * utils::SubCommand::required ( bool required = true,
bool force = true )

Definition at line 216 of file SubCommand.cpp.

216 {
217 requiredCount += required ? 1 : -1;
218
219 required = force ? required : requiredCount > 0;
220
221 subCommandApp->required(required);
222
224 if (parent != nullptr) {
225 if (required) {
226 parent->needs(this);
227 }
228
229 parent->required(this, required);
230 }
231
232 return this;
233 }
SubCommand * required(bool required=true, bool force=true)
SubCommand * getParent() const

References getParent(), needs(), required(), requiredCount, and subCommandApp.

Referenced by required(), and required().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ required() [2/3]

SubCommand * utils::SubCommand::required ( CLI::Option * option,
bool required = true )

Definition at line 264 of file SubCommand.cpp.

264 {
265 if (option->get_required() != required) {
266 option->required(required);
267
268 if (required) {
269 subCommandApp->needs(option);
270 option->default_str("");
271 } else {
272 subCommandApp->remove_needs(option);
273 }
274
275 this->required(required, false);
276 }
277
278 return this;
279 }

References required(), and subCommandApp.

Referenced by subcommand::ConfigWWW::ConfigWWW(), and subcommand::ConfigWWW::setHtmlRoot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ required() [3/3]

SubCommand * utils::SubCommand::required ( SubCommand * subCommand,
bool required = true )

Definition at line 235 of file SubCommand.cpp.

235 {
236 if (subCommandApp->get_required() != required) {
237 if (required) {
238 needs(subCommand);
239
240 for (const auto& sub : subCommand->subCommandApp->get_subcommands([](const CLI::App* sc) -> bool {
241 return sc->get_required();
242 })) {
243 subCommand->subCommandApp->needs(sub);
244 }
245 } else {
246 needs(subCommand, false);
247
248 for (const auto& sub : subCommand->subCommandApp->get_subcommands([](const CLI::App* sc) -> bool {
249 return sc->get_required();
250 })) {
251 subCommand->subCommandApp->remove_needs(sub);
252 }
253 }
254
255 this->required(required, false);
256
257 subCommand->subCommandApp->required(required);
258 subCommand->subCommandApp->ignore_case(required);
259 }
260
261 return this;
262 }

References needs(), required(), and subCommandApp.

Referenced by required().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setConfig()

CLI::Option * utils::SubCommand::setConfig ( const std::string & defaultConfigFile) const

Definition at line 164 of file SubCommand.cpp.

164 {
165 return subCommandApp
166 ->set_config( //
167 "-c,--config-file",
168 defaultConfigFile,
169 "Read a config file",
170 false) //
171 ->take_all()
172 ->type_name("configfile")
173 ->check(!CLI::ExistingDirectory);
174 }

References subCommandApp.

Referenced by utils::ConfigRoot::addRootOptions().

Here is the caller graph for this function:

◆ setConfigurable()

CLI::Option * utils::SubCommand::setConfigurable ( CLI::Option * option,
bool configurable ) const
protected

Definition at line 437 of file SubCommand.cpp.

437 {
438 return option //
439 ->configurable(configurable)
440 ->group(subCommandApp->get_formatter()->get_label(configurable ? "Persistent Options" : "Nonpersistent Options"));
441 }

References subCommandApp.

Referenced by utils::ConfigRoot::addRootOptions(), ConfigDb::ConfigDb(), net::config::ConfigInstance::ConfigInstance(), net::config::ConfigInstance::configurable(), initialize(), and SubCommand().

Here is the caller graph for this function:

◆ setDefaultValue()

template<typename ValueTypeT>
CLI::Option * utils::SubCommand::setDefaultValue ( CLI::Option * option,
const ValueTypeT & value,
bool clear = true ) const
protected

Definition at line 367 of file SubCommand.h.

367 {
368 try {
369 option->default_val(value);
370
371 if (clear) {
372 option->clear();
373 }
374 } catch (const CLI::ParseError&) {
375 option = nullptr;
376 }
377
378 return option;
379 }

Referenced by addFlagFunction(), net::in6::stream::config::ConfigSocketClient::ConfigSocketClient(), net::in::stream::config::ConfigSocketClient::ConfigSocketClient(), net::in6::stream::config::ConfigSocketServer::ConfigSocketServer(), net::in::stream::config::ConfigSocketServer::ConfigSocketServer(), net::config::ConfigPhysicalSocketServer::setAcceptsPerTick(), net::config::ConfigPhysicalSocketServer::setAcceptTimeout(), net::config::ConfigPhysicalSocketServer::setBacklog(), net::config::ConfigTls::setCaCert(), net::config::ConfigTls::setCaCertAcceptUnknown(), net::config::ConfigTls::setCaCertDir(), net::config::ConfigTls::setCaCertUseDefaultDir(), net::config::ConfigTls::setCert(), net::config::ConfigTls::setCertKey(), net::config::ConfigTls::setCertKeyPassword(), net::config::ConfigTls::setCipherList(), net::config::ConfigPhysicalSocketClient::setConnectTimeout(), net::config::ConfigInstance::setDisabled(), net::in6::stream::config::ConfigSocketClient::setDisableNagleAlgorithm(), net::in6::stream::config::ConfigSocketServer::setDisableNagleAlgorithm(), net::in::stream::config::ConfigSocketClient::setDisableNagleAlgorithm(), net::in::stream::config::ConfigSocketServer::setDisableNagleAlgorithm(), net::config::ConfigTlsServer::setForceSni(), web::http::client::ConfigHTTP::setHostHeader(), subcommand::ConfigWWW::setHtmlRoot(), net::config::ConfigTls::setInitTimeout(), net::in6::stream::config::ConfigSocketServer::setIPv6Only(), web::http::client::ConfigHTTP::setPipelinedRequests(), net::config::ConfigConnection::setReadBlockSize(), net::config::ConfigConnection::setReadTimeout(), net::config::ConfigPhysicalSocketClient::setReconnect(), net::config::ConfigPhysicalSocketClient::setReconnectTime(), net::config::ConfigPhysicalSocket::setRetry(), net::config::ConfigPhysicalSocket::setRetryBase(), net::config::ConfigPhysicalSocket::setRetryJitter(), net::config::ConfigPhysicalSocket::setRetryLimit(), net::config::ConfigPhysicalSocket::setRetryOnFatal(), net::config::ConfigPhysicalSocket::setRetryTimeout(), net::config::ConfigPhysicalSocket::setRetryTries(), net::in6::stream::config::ConfigSocketServer::setReuseAddress(), net::in::stream::config::ConfigSocketServer::setReuseAddress(), net::in6::stream::config::ConfigSocketServer::setReusePort(), net::in::stream::config::ConfigSocketServer::setReusePort(), net::config::ConfigTls::setShutdownTimeout(), net::config::ConfigTlsClient::setSni(), net::config::ConfigTls::setSslOptions(), net::config::ConfigConnection::setTerminateTimeout(), net::config::ConfigConnection::setWriteBlockSize(), and net::config::ConfigConnection::setWriteTimeout().

Here is the caller graph for this function:

◆ setLogFile()

CLI::Option * utils::SubCommand::setLogFile ( const std::string & defaultLogFile) const

Definition at line 176 of file SubCommand.cpp.

176 {
177 return addOption("-l,--log-file", "Log file", "logFile", defaultLogFile, !CLI::ExistingDirectory);
178 }

References addOption().

Referenced by utils::ConfigRoot::addRootOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRequireCallback()

SubCommand * utils::SubCommand::setRequireCallback ( const std::function< void(void)> & callback)

Definition at line 192 of file SubCommand.cpp.

192 {
193 subCommandApp->require_callback(callback);
194
195 return this;
196 }

References subCommandApp.

◆ setVersionFlag()

CLI::Option * utils::SubCommand::setVersionFlag ( const std::string & version) const

Definition at line 180 of file SubCommand.cpp.

180 {
181 return subCommandApp->set_version_flag("-v,--version", version, "Framework version");
182 }
std::string version() const

References subCommandApp.

Referenced by utils::ConfigRoot::addRootOptions().

Here is the caller graph for this function:

◆ version()

std::string utils::SubCommand::version ( ) const

Definition at line 133 of file SubCommand.cpp.

133 {
134 return subCommandApp->version();
135 }

References subCommandApp.

Referenced by utils::ConfigRoot::parse2().

Here is the caller graph for this function:

Member Data Documentation

◆ aliases

std::map< std::string, std::string > utils::SubCommand::aliases
staticprotected

Definition at line 242 of file SubCommand.h.

Referenced by utils::ConfigRoot::parse2().

◆ childSubCommands

std::set<SubCommand*> utils::SubCommand::childSubCommands
private

Definition at line 256 of file SubCommand.h.

Referenced by removeSubCommand().

◆ commandlineOpt

CLI::Option* utils::SubCommand::commandlineOpt = nullptr
private

Definition at line 265 of file SubCommand.h.

Referenced by SubCommand().

◆ commandlineTriggerApp

CLI::App * utils::SubCommand::commandlineTriggerApp = nullptr
staticprotected

◆ final

bool utils::SubCommand::final
private

Definition at line 258 of file SubCommand.h.

Referenced by newSubCommand(), and SubCommand().

◆ helpOpt

CLI::Option* utils::SubCommand::helpOpt = nullptr
protected

Definition at line 261 of file SubCommand.h.

Referenced by addSubCommandApp(), utils::ConfigRoot::parse1(), and SubCommand().

◆ helpTriggerApp

CLI::App * utils::SubCommand::helpTriggerApp = nullptr
staticprotected

◆ name

std::string utils::SubCommand::name
private

Definition at line 252 of file SubCommand.h.

Referenced by getName(), and SubCommand().

◆ parent

SubCommand* utils::SubCommand::parent
private

Definition at line 253 of file SubCommand.h.

Referenced by getParent(), removeSubCommand(), and SubCommand().

◆ requiredCount

int utils::SubCommand::requiredCount = 0
private

Definition at line 267 of file SubCommand.h.

Referenced by required().

◆ sectionFormatter

std::shared_ptr< CLI::Formatter > utils::SubCommand::sectionFormatter = makeSectionFormatter()
staticprotected

Definition at line 240 of file SubCommand.h.

◆ selfAnchoredSubCommandApp

std::shared_ptr<AppWithPtr> utils::SubCommand::selfAnchoredSubCommandApp
private

Definition at line 255 of file SubCommand.h.

Referenced by SubCommand().

◆ showConfigOpt

CLI::Option* utils::SubCommand::showConfigOpt = nullptr
private

Definition at line 264 of file SubCommand.h.

Referenced by SubCommand().

◆ showConfigTriggerApp

CLI::App * utils::SubCommand::showConfigTriggerApp = nullptr
staticprotected

◆ subCommandApp


The documentation for this class was generated from the following files: