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
std::string configToStr () const
std::string help (const CLI::App *helpApp, const CLI::AppFormatMode &mode) const
bool hasParent () const
SubCommandgetParent () const
SubCommandallowExtras (bool allow=true)
SubCommandforceUnrequired (bool unrequired=true)
SubCommandrequired (bool required=true)
SubCommandrequired (CLI::Option *option, bool required=true)
bool getRequired () const
SubCommandneeds (SubCommand *subCommand, bool needs=true)
SubCommandsetRequireCallback (const std::function< void(void)> &callback)
SubCommandfinalCallback (const std::function< void()> &finalCallback)
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 * 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
CLI::Option * getOption (const std::string &name) const
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

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 ()
CLI::Option * addConfigFlag (const std::string &defaultConfigFile) const
CLI::Option * addLogFileFlag (const std::string &defaultLogFile) const
CLI::Option * addVersionFlag (const std::string &version) const

Static Protected Member Functions

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

Protected Attributes

CLI::Option * helpOpt = nullptr
CLI::Option * showConfigOpt = nullptr
CLI::Option * commandlineOpt = nullptr

Static Protected Attributes

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
int requiredCount = 0
bool requiredForced = false
bool final

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 ->type_name("MODE")
91 ->take_first()
92 ->check(CLI::IsMember({"standard", "exact"}))
93 ->trigger_on_parse(),
94 false);
95
97 ->add_flag_function(
98 "-s,--show-config",
99 [subCommandApp = this->subCommandApp](std::size_t) {
101 },
102 "Show current configuration and exit")
103 ->take_first()
104 ->disable_flag_override()
105 ->configurable(false)
106 ->trigger_on_parse(),
107 false);
108
110 ->add_flag_function(
111 "--command-line{standard}",
112 [subCommandApp = this->subCommandApp]([[maybe_unused]] std::int64_t count) {
114 },
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")
120 ->type_name("MODE")
121 ->take_first()
122 ->check(CLI::IsMember({"standard", "active", "complete", "required"}))
123 ->trigger_on_parse(),
124 false);
125 }
126 }
std::shared_ptr< AppWithPtr > selfAnchoredSubCommandApp
Definition SubCommand.h:258
static CLI::App * showConfigTriggerApp
Definition SubCommand.h:242
CLI::Option * commandlineOpt
Definition SubCommand.h:255
CLI::Option * helpOpt
Definition SubCommand.h:253
AppWithPtr * subCommandApp
Definition SubCommand.h:248
SubCommand * parent
Definition SubCommand.h:250
static CLI::App * helpTriggerApp
Definition SubCommand.h:241
std::string name
Definition SubCommand.h:249
CLI::Option * showConfigOpt
Definition SubCommand.h:254
static CLI::App * commandlineTriggerApp
Definition SubCommand.h:243
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 128 of file SubCommand.cpp.

128 {
130 }

References removeSubCommand().

Here is the call graph for this function:

Member Function Documentation

◆ addConfigFlag()

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

Definition at line 296 of file SubCommand.cpp.

296 {
297 return subCommandApp
298 ->set_config( //
299 "-c,--config-file",
300 defaultConfigFile,
301 "Read a config file",
302 false) //
303 ->take_all()
304 ->type_name("configfile")
305 ->check(!CLI::ExistingDirectory);
306 }

References subCommandApp.

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

Here is the caller graph for this function:

◆ 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 339 of file SubCommand.cpp.

342 {
343 return initialize(subCommandApp //
344 ->add_flag(name, description),
345 typeName,
346 validator,
347 !subCommandApp->get_disabled());
348 }
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 351 of file SubCommand.h.

355 {
356 return setDefaultValue(addFlag(name, description, typeName, additionalValidator), defaultValue);
357 }
CLI::Option * setDefaultValue(CLI::Option *option, const ValueTypeT &value, bool clear=true) const
Definition SubCommand.h:360
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 350 of file SubCommand.cpp.

354 {
355 CLI::Option* opt = subCommandApp //
356 ->add_flag_function(
357 name,
358 [callback](std::int64_t) {
359 callback();
360 },
362 ->type_name(typeName)
363 ->check(validator)
364 ->take_last();
365 if (opt->get_configurable()) {
366 opt->group(subCommandApp->get_formatter()->get_label("Persistent Options"));
367 }
368
369 return opt;
370 }

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 372 of file SubCommand.cpp.

377 {
378 return setDefaultValue(addFlagFunction(name, callback, description, typeName, validator), defaultValue);
379 }
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:

◆ addLogFileFlag()

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

Definition at line 308 of file SubCommand.cpp.

308 {
309 return addOption("-l,--log-file", "Log file", "logFile", defaultLogFile, !CLI::ExistingDirectory);
310 }
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().

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 316 of file SubCommand.cpp.

319 {
320 return initialize(subCommandApp //
321 ->add_option(name, description),
322 typeName,
323 validator,
324 !subCommandApp->get_disabled());
325 }

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 312 of file SubCommand.h.

316 {
317 return setDefaultValue(addOption(name, description, typeName, additionalValidator), defaultValue);
318 }

References addOption().

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

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 327 of file SubCommand.cpp.

331 {
332 return initialize(subCommandApp //
333 ->add_option_function(name, callback, description),
334 typeName,
335 validator,
336 !subCommandApp->get_disabled());
337 }

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 341 of file SubCommand.h.

346 {
347 return setDefaultValue(addOptionFunction(name, callback, description, typeName, validator), defaultValue);
348 }
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 321 of file SubCommand.h.

325 {
326 return initialize(
327 subCommandApp->add_option(name, variable, description), typeName, additionalValidator, !subCommandApp->get_disabled());
328 }

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 331 of file SubCommand.h.

336 {
337 return setDefaultValue(addOptionVariable(name, variable, description, typeName, additionalValidator), defaultValue);
338 }
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:321

◆ addSubCommandApp()

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

Definition at line 282 of file SubCommand.cpp.

282 {
283 if (subCommandApp->get_subcommands({}).empty()) {
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"})); // replace, do not append
290 }
291 }
292
293 subCommandApp->add_subcommand(subCommand);
294 }

References helpOpt, and subCommandApp.

Referenced by SubCommand().

Here is the caller graph for this function:

◆ addVersionFlag()

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

Definition at line 312 of file SubCommand.cpp.

312 {
313 return subCommandApp->set_version_flag("-v,--version", version, "Framework version");
314 }
std::string version() const

References subCommandApp.

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

Here is the caller graph for this function:

◆ allowExtras()

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

Definition at line 191 of file SubCommand.cpp.

191 {
192 subCommandApp->allow_extras(allow);
193
194 return this;
195 }

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 175 of file SubCommand.cpp.

175 {
176 return subCommandApp->config_to_str(true, true);
177 }

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 144 of file SubCommand.cpp.

144 {
145 subCommandApp->description(description);
146
147 return this;
148 }

References subCommandApp.

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

Here is the caller graph for this function:

◆ finalCallback()

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

Definition at line 276 of file SubCommand.cpp.

276 {
277 subCommandApp->final_callback(finalCallback);
278
279 return this;
280 }
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 150 of file SubCommand.cpp.

150 {
151 subCommandApp->footer(footer);
152
153 return this;
154 }
SubCommand * footer(const std::string &footer)

References subCommandApp.

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

Here is the caller graph for this function:

◆ forceUnrequired()

SubCommand * utils::SubCommand::forceUnrequired ( bool unrequired = true)

Definition at line 197 of file SubCommand.cpp.

197 {
198 const bool previouslyRequired = subCommandApp->get_required();
199 const bool countedRequired = subCommandApp->get_ignore_case();
200
201 requiredForced = unrequired;
202
203 const bool effectiveRequired = requiredForced ? false : countedRequired;
204 if (previouslyRequired != effectiveRequired) {
205 subCommandApp->required(effectiveRequired);
206
207 if (hasParent()) {
209 parent->needs(this, effectiveRequired);
210 parent->required(effectiveRequired);
211 }
212 }
213
214 return this;
215 }
bool hasParent() const
SubCommand * getParent() const

References getParent(), hasParent(), needs(), required(), requiredForced, 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:

◆ getCommandlineTriggerApp()

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

Definition at line 399 of file SubCommand.cpp.

399 {
401 }

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 391 of file SubCommand.cpp.

391 {
392 return helpTriggerApp;
393 }

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 132 of file SubCommand.cpp.

132 {
133 return name;
134 }

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 381 of file SubCommand.cpp.

381 {
382 return subCommandApp->get_option_no_throw(name);
383 }

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 187 of file SubCommand.cpp.

187 {
188 return parent;
189 }

References parent.

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

Here is the caller graph for this function:

◆ getRequired()

bool utils::SubCommand::getRequired ( ) const

Definition at line 256 of file SubCommand.cpp.

256 {
257 return subCommandApp->get_required();
258 }

References subCommandApp.

◆ getShowConfigTriggerApp()

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

Definition at line 395 of file SubCommand.cpp.

395 {
397 }

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 286 of file SubCommand.h.

286 {
287 auto* appWithPtr = subCommandApp->get_subcommand_no_throw(std::string(RequestedSubCommand::NAME));
288
289 AppWithPtr* subCommandApp = nullptr;
290
291 if (appWithPtr != nullptr) {
292 subCommandApp = dynamic_cast<utils::AppWithPtr*>(appWithPtr);
293 }
294
295 return subCommandApp != nullptr ? dynamic_cast<RequestedSubCommand*>(subCommandApp->getPtr()) : nullptr;
296 }

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 299 of file SubCommand.h.

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

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

Here is the call graph for this function:

◆ hasParent()

bool utils::SubCommand::hasParent ( ) const

Definition at line 183 of file SubCommand.cpp.

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

References subCommandApp.

Referenced by forceUnrequired(), and required().

Here is the caller graph for this function:

◆ help()

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

Definition at line 179 of file SubCommand.cpp.

179 {
180 return subCommandApp->help(helpApp, "", mode);
181 }

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 404 of file SubCommand.cpp.

404 {
405 return setConfigurable(option, configurable) //
406 ->type_name(typeName)
407 ->check(validator);
408 }

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 260 of file SubCommand.cpp.

260 {
261 if (needs) {
262 subCommandApp->needs(subCommand->subCommandApp);
263 } else {
264 subCommandApp->remove_needs(subCommand->subCommandApp);
265 }
266
267 return this;
268 }
SubCommand * needs(SubCommand *subCommand, bool needs=true)

References subCommandApp.

Referenced by forceUnrequired(), 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 return !final ? dynamic_cast<NewSubCommand*>(*childSubCommands.insert(new NewSubCommand(this, std::forward(args)...)).first)
282 : nullptr;
283 }
std::set< SubCommand * > childSubCommands
Definition SubCommand.h:262

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 140 of file SubCommand.cpp.

140 {
141 subCommandApp->parse(argc, argv);
142 }

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 156 of file SubCommand.cpp.

156 {
157 while (!childSubCommands.empty()) {
158 SubCommand* child = *childSubCommands.begin();
159 childSubCommands.erase(child);
160
161 delete child;
162 }
163
164 if (parent != nullptr) {
165 parent->childSubCommands.erase(this);
166
167 if (parent->subCommandApp != nullptr && subCommandApp != nullptr) {
168 parent->subCommandApp->remove_subcommand(subCommandApp);
169 }
170
171 parent = nullptr;
172 }
173 }

References childSubCommands, parent, and subCommandApp.

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

Here is the caller graph for this function:

◆ required() [1/2]

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

Definition at line 217 of file SubCommand.cpp.

217 {
218 const bool previousEffectiveRequired = subCommandApp->get_required();
219
220 requiredCount += required ? 1 : -1;
221 const bool countedRequired = requiredCount > 0;
222 const bool effectiveRequired = requiredForced ? false : countedRequired;
223
224 subCommandApp->ignore_case(countedRequired);
225 if (subCommandApp->get_required() != effectiveRequired) {
226 subCommandApp->required(effectiveRequired);
227 }
228
229 if (hasParent() && previousEffectiveRequired != effectiveRequired) {
231
232 parent->needs(this, effectiveRequired);
233 parent->required(effectiveRequired);
234 }
235
236 return this;
237 }
SubCommand * required(bool required=true)

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

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

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

◆ required() [2/2]

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

Definition at line 239 of file SubCommand.cpp.

239 {
240 if (option->get_required() != required) {
241 option->required(required);
242
243 if (required) {
244 subCommandApp->needs(option);
245 option->default_str("");
246 } else {
247 subCommandApp->remove_needs(option);
248 }
249
250 this->required(required);
251 }
252
253 return this;
254 }

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:

◆ setConfigurable()

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

Definition at line 385 of file SubCommand.cpp.

385 {
386 return option //
387 ->configurable(configurable)
388 ->group(subCommandApp->get_formatter()->get_label(configurable ? "Persistent Options" : "Nonpersistent Options"));
389 }

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

Definition at line 360 of file SubCommand.h.

360 {
361 try {
362 option->default_val(value);
363
364 if (clear) {
365 option->clear();
366 }
367 } catch (const CLI::ParseError&) {
368 option = nullptr;
369 }
370
371 return option;
372 }

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::setCaCertDirUseDefault(), 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:

◆ setRequireCallback()

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

Definition at line 270 of file SubCommand.cpp.

270 {
271 subCommandApp->require_callback(callback);
272
273 return this;
274 }

References subCommandApp.

◆ version()

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

Definition at line 136 of file SubCommand.cpp.

136 {
137 return subCommandApp->version();
138 }

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 239 of file SubCommand.h.

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

◆ childSubCommands

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

Definition at line 262 of file SubCommand.h.

Referenced by removeSubCommand().

◆ commandlineOpt

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

Definition at line 255 of file SubCommand.h.

Referenced by SubCommand().

◆ commandlineTriggerApp

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

◆ final

bool utils::SubCommand::final
private

Definition at line 267 of file SubCommand.h.

Referenced by SubCommand().

◆ helpOpt

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

Definition at line 253 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 249 of file SubCommand.h.

Referenced by getName(), and SubCommand().

◆ parent

SubCommand* utils::SubCommand::parent
private

Definition at line 250 of file SubCommand.h.

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

◆ requiredCount

int utils::SubCommand::requiredCount = 0
private

Definition at line 264 of file SubCommand.h.

Referenced by required().

◆ requiredForced

bool utils::SubCommand::requiredForced = false
private

Definition at line 265 of file SubCommand.h.

Referenced by forceUnrequired(), and required().

◆ selfAnchoredSubCommandApp

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

Definition at line 258 of file SubCommand.h.

Referenced by SubCommand().

◆ showConfigOpt

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

Definition at line 254 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: