Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
CLI::Option_group Class Reference

Extension of App to better manage groups of options. More...

#include <CLI11.hpp>

Inheritance diagram for CLI::Option_group:
Collaboration diagram for CLI::Option_group:

Public Member Functions

 Option_group (std::string group_description, std::string group_name, App *parent)
 
Optionadd_option (Option *opt)
 Add an existing option to the Option_group.
 
void add_options (Option *opt)
 Add an existing option to the Option_group.
 
template<typename... Args>
void add_options (Option *opt, Args... args)
 Add a bunch of options to the group.
 
Appadd_subcommand (App *subcom)
 Add an existing subcommand to be a member of an option_group.
 
Optionadd_option (std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
 
template<typename AssignTo , typename ConvertTo = AssignTo, enable_if_t<!std::is_const< ConvertTo >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, AssignTo &variable, std::string option_description="", bool defaulted=false)
 Add option for assigning to a variable.
 
Optionadd_option (std::string option_name)
 Add option with no description or variable assignment.
 
template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, T &option_description)
 Add option with description but with no variable assignment or callback.
 
Appadd_subcommand (std::string subcommand_name="", std::string subcommand_description="")
 Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
 
Appadd_subcommand (CLI::App_p subcom)
 Add a previously created app as a subcommand.
 
- Public Member Functions inherited from CLI::App
void _move_option (Option *opt, App *app)
 function that could be used by subclasses of App to shift options around into subcommands
 
 App (std::string app_description="", std::string app_name="")
 Create a new program. Pass in the same arguments as main(), along with a help string.
 
 App (const App &)=delete
 
Appoperator= (const App &)=delete
 
virtual ~App ()=default
 virtual destructor
 
Appcallback (std::function< void()> app_callback)
 
Appfinal_callback (std::function< void()> app_callback)
 
Appparse_complete_callback (std::function< void()> pc_callback)
 
Apppreparse_callback (std::function< void(std::size_t)> pp_callback)
 
Appname (std::string app_name="")
 Set a name for the app (empty will use parser to set the name)
 
Appalias (std::string app_name)
 Set an alias for the app.
 
Appallow_extras (bool allow=true)
 Remove the error when extras are left over on the command line.
 
Apprequired (bool require=true)
 Remove the error when extras are left over on the command line.
 
Appdisabled (bool disable=true)
 Disable the subcommand or option group.
 
Appdisabled_by_default (bool disable=true)
 Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disabled.
 
Appenabled_by_default (bool enable=true)
 
Appimmediate_callback (bool immediate=true)
 Set the subcommand callback to be executed immediately on subcommand completion.
 
Appvalidate_positionals (bool validate=true)
 Set the subcommand to validate positional arguments before assigning.
 
Appallow_config_extras (bool allow=true)
 ignore extras in config files
 
Appallow_config_extras (config_extras_mode mode)
 ignore extras in config files
 
Appprefix_command (bool allow=true)
 Do not parse anything after the first unrecognized option and return.
 
Appignore_case (bool value=true)
 Ignore case. Subcommands inherit value.
 
Appallow_windows_style_options (bool value=true)
 
Apppositionals_at_end (bool value=true)
 Specify that the positional arguments are only at the end of the sequence.
 
Appconfigurable (bool value=true)
 Specify that the subcommand can be triggered by a config file.
 
Appignore_underscore (bool value=true)
 Ignore underscore. Subcommands inherit value.
 
Appformatter (std::shared_ptr< FormatterBase > fmt)
 Set the help formatter.
 
Appformatter_fn (std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
 Set the help formatter.
 
Appconfig_formatter (std::shared_ptr< Config > fmt)
 Set the config formatter.
 
bool parsed () const
 Check to see if this subcommand was parsed, true only if received on command line.
 
OptionDefaultsoption_defaults ()
 Get the OptionDefault object, to set option defaults.
 
Appadd_subcommand (std::string subcommand_name="", std::string subcommand_description="")
 Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
 
Appadd_subcommand (CLI::App_p subcom)
 Add a previously created app as a subcommand.
 
bool remove_subcommand (App *subcom)
 Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
 
Appget_subcommand (const App *subcom) const
 
Appget_subcommand (std::string subcom) const
 Check to see if a subcommand is part of this command (text version)
 
Appget_subcommand (int index=0) const
 Get a pointer to subcommand by index.
 
CLI::App_p get_subcommand_ptr (App *subcom) const
 Check to see if a subcommand is part of this command and get a shared_ptr to it.
 
CLI::App_p get_subcommand_ptr (std::string subcom) const
 Check to see if a subcommand is part of this command (text version)
 
CLI::App_p get_subcommand_ptr (int index=0) const
 Get an owning pointer to subcommand by index.
 
Appget_option_group (std::string group_name) const
 Check to see if an option group is part of this App.
 
std::size_t count () const
 
std::size_t count_all () const
 
Appgroup (std::string group_name)
 Changes the group membership.
 
Apprequire_subcommand ()
 The argumentless form of require subcommand requires 1 or more subcommands.
 
Apprequire_subcommand (int value)
 
Apprequire_subcommand (std::size_t min, std::size_t max)
 
Apprequire_option ()
 The argumentless form of require option requires 1 or more options be used.
 
Apprequire_option (int value)
 
Apprequire_option (std::size_t min, std::size_t max)
 
Appfallthrough (bool value=true)
 
 operator bool () const
 
virtual void pre_callback ()
 
std::size_t count (std::string option_name) const
 Counts the number of times the given option was passed.
 
std::vector< App * > get_subcommands () const
 
std::vector< const App * > get_subcommands (const std::function< bool(const App *)> &filter) const
 
std::vector< App * > get_subcommands (const std::function< bool(App *)> &filter)
 
bool got_subcommand (const App *subcom) const
 Check to see if given subcommand was selected.
 
bool got_subcommand (std::string subcommand_name) const
 Check with name instead of pointer to see if subcommand was selected.
 
Appexcludes (Option *opt)
 Sets excluded options for the subcommand.
 
Appexcludes (App *app)
 Sets excluded subcommands for the subcommand.
 
Appneeds (Option *opt)
 
Appneeds (App *app)
 
bool remove_excludes (Option *opt)
 Removes an option from the excludes list of this subcommand.
 
bool remove_excludes (App *app)
 Removes a subcommand from the excludes list of this subcommand.
 
bool remove_needs (Option *opt)
 Removes an option from the needs list of this subcommand.
 
bool remove_needs (App *app)
 Removes a subcommand from the needs list of this subcommand.
 
std::shared_ptr< FormatterBaseget_formatter () const
 Access the formatter.
 
std::shared_ptr< Configget_config_formatter () const
 Access the config formatter.
 
std::shared_ptr< ConfigBaseget_config_formatter_base () const
 Access the config formatter as a configBase pointer.
 
std::string get_description () const
 Get the app or subcommand description.
 
Appdescription (std::string app_description)
 Set the description of the app.
 
std::vector< const Option * > get_options (const std::function< bool(const Option *)> filter={}) const
 Get the list of options (user facing function, so returns raw pointers), has optional filter function.
 
std::vector< Option * > get_options (const std::function< bool(Option *)> filter={})
 Non-const version of the above.
 
Optionget_option_no_throw (std::string option_name) noexcept
 Get an option by name (noexcept non-const version)
 
const Optionget_option_no_throw (std::string option_name) const noexcept
 Get an option by name (noexcept const version)
 
const Optionget_option (std::string option_name) const
 Get an option by name.
 
Optionget_option (std::string option_name)
 Get an option by name (non-const version)
 
const Optionoperator[] (const std::string &option_name) const
 Shortcut bracket operator for getting a pointer to an option.
 
const Optionoperator[] (const char *option_name) const
 Shortcut bracket operator for getting a pointer to an option.
 
bool get_ignore_case () const
 Check the status of ignore_case.
 
bool get_ignore_underscore () const
 Check the status of ignore_underscore.
 
bool get_fallthrough () const
 Check the status of fallthrough.
 
bool get_allow_windows_style_options () const
 Check the status of the allow windows style options.
 
bool get_positionals_at_end () const
 Check the status of the allow windows style options.
 
bool get_configurable () const
 Check the status of the allow windows style options.
 
const std::string & get_group () const
 Get the group of this subcommand.
 
std::string get_footer () const
 Generate and return the footer.
 
std::size_t get_require_subcommand_min () const
 Get the required min subcommand value.
 
std::size_t get_require_subcommand_max () const
 Get the required max subcommand value.
 
std::size_t get_require_option_min () const
 Get the required min option value.
 
std::size_t get_require_option_max () const
 Get the required max option value.
 
bool get_prefix_command () const
 Get the prefix command status.
 
bool get_allow_extras () const
 Get the status of allow extras.
 
bool get_required () const
 Get the status of required.
 
bool get_disabled () const
 Get the status of disabled.
 
bool get_immediate_callback () const
 Get the status of disabled.
 
bool get_disabled_by_default () const
 Get the status of disabled by default.
 
bool get_enabled_by_default () const
 Get the status of disabled by default.
 
bool get_validate_positionals () const
 Get the status of validating positionals.
 
config_extras_mode get_allow_config_extras () const
 Get the status of allow extras.
 
Optionget_help_ptr ()
 Get a pointer to the help flag.
 
const Optionget_help_ptr () const
 Get a pointer to the help flag. (const)
 
const Optionget_help_all_ptr () const
 Get a pointer to the help all flag. (const)
 
Optionget_config_ptr ()
 Get a pointer to the config option.
 
const Optionget_config_ptr () const
 Get a pointer to the config option. (const)
 
Appget_parent ()
 Get the parent of this subcommand (or nullptr if master app)
 
const Appget_parent () const
 Get the parent of this subcommand (or nullptr if master app) (const version)
 
const std::string & get_name () const
 Get the name of the current app.
 
const std::vector< std::string > & get_aliases () const
 Get the aliases of the current app.
 
Appclear_aliases ()
 clear all the aliases of the current App
 
std::string get_display_name () const
 Get a display name for an app.
 
bool check_name (std::string name_to_check) const
 Check the name, case insensitive and underscore insensitive if set.
 
std::vector< std::string > get_groups () const
 Get the groups available directly from this option (in order)
 
const std::vector< Option * > & parse_order () const
 This gets a vector of pointers with the original parse order.
 
std::vector< std::string > remaining (bool recurse=false) const
 This returns the missing options from the current subcommand.
 
std::vector< std::string > remaining_for_passthrough (bool recurse=false) const
 This returns the missing options in a form ready for processing by another command line program.
 
std::size_t remaining_size (bool recurse=false) const
 This returns the number of remaining options, minus the – separator.
 
void clear ()
 Reset the parsed data.
 
void parse (int argc, const char *const *argv)
 
void parse (std::string commandline, bool program_name_included=false)
 
void parse (std::vector< std::string > &args)
 
void parse (std::vector< std::string > &&args)
 The real work is done here. Expects a reversed vector.
 
void failure_message (std::function< std::string(const App *, const Error &e)> function)
 Provide a function to print a help message. The function gets access to the App pointer and error.
 
int exit (const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
 Print a nice error message and return the exit code.
 
Appfooter (std::string footer_string)
 Set footer.
 
Appfooter (std::function< std::string()> footer_function)
 Set footer.
 
std::string config_to_str (bool default_also=false, bool write_description=false) const
 
std::string help (std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
 
Optionadd_option (std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
 
template<typename AssignTo , typename ConvertTo = AssignTo, enable_if_t<!std::is_const< ConvertTo >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, AssignTo &variable, std::string option_description="", bool defaulted=false)
 Add option for assigning to a variable.
 
template<typename T >
Optionadd_option_function (std::string option_name, const std::function< void(const T &)> &func, std::string option_description="")
 Add option for a callback of a specific type.
 
Optionadd_option (std::string option_name)
 Add option with no description or variable assignment.
 
template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, T &option_description)
 Add option with description but with no variable assignment or callback.
 
Optionset_help_flag (std::string flag_name="", const std::string &help_description="")
 Set a help flag, replace the existing one if present.
 
Optionset_help_all_flag (std::string help_name="", const std::string &help_description="")
 Set a help all flag, replaced the existing one if present.
 
Optionadd_flag (std::string flag_name)
 Add a flag with no description or variable assignment.
 
template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_description)
 
template<typename T , enable_if_t< std::is_integral< T >::value &&!is_bool< T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_count, std::string flag_description="")
 
template<typename T , enable_if_t<!is_vector< T >::value &&!std::is_const< T >::value &&(!std::is_integral< T >::value||is_bool< T >::value) &&!std::is_constructible< std::function< void(int)>, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_result, std::string flag_description="")
 
template<typename T , enable_if_t<!std::is_assignable< std::function< void(int64_t)>, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
 Vector version to capture multiple flags.
 
Optionadd_flag_callback (std::string flag_name, std::function< void(void)> function, std::string flag_description="")
 Add option for callback that is triggered with a true flag and takes no arguments.
 
Optionadd_flag_function (std::string flag_name, std::function< void(int64_t)> function, std::string flag_description="")
 Add option for callback with an integer value.
 
template<typename T >
Optionadd_set (std::string option_name, T &member, std::set< T > options, std::string option_description="")
 Add set of options (No default, temp reference, such as an inline set) DEPRECATED.
 
template<typename T >
Optionadd_mutable_set (std::string option_name, T &member, const std::set< T > &options, std::string option_description="")
 Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED.
 
template<typename T >
Optionadd_set (std::string option_name, T &member, std::set< T > options, std::string option_description, bool defaulted)
 Add set of options (with default, static set, such as an inline set) DEPRECATED.
 
template<typename T >
Optionadd_mutable_set (std::string option_name, T &member, const std::set< T > &options, std::string option_description, bool defaulted)
 Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED.
 
template<typename T , typename XC = double>
Optionadd_complex (std::string option_name, T &variable, std::string option_description="", bool defaulted=false, std::string label="COMPLEX")
 Add a complex number.
 
Optionset_config (std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false)
 Set a configuration ini file option, or clear it if no name passed.
 
bool remove_option (Option *opt)
 Removes an option from the App. Takes an option pointer. Returns true if found and removed.
 
template<typename T = Option_group>
Tadd_option_group (std::string group_name, std::string group_description="")
 creates an option group as part of the given app
 

Additional Inherited Members

- Protected Types inherited from CLI::App
enum class  startup_mode : char { stable , enabled , disabled }
 
using missing_t = std::vector<std::pair<detail::Classifier, std::string>>
 
- Protected Member Functions inherited from CLI::App
 App (std::string app_description, std::string app_name, App *parent)
 Special private constructor for subcommand.
 
void _validate () const
 
void _configure ()
 
void run_callback (bool final_mode=false)
 Internal function to run (App) callback, bottom up.
 
bool _valid_subcommand (const std::string &current, bool ignore_used=true) const
 Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached.
 
detail::Classifier _recognize (const std::string &current, bool ignore_used_subcommands=true) const
 Selects a Classifier enum based on the type of the current argument.
 
void _process_config_file ()
 Read and process a configuration file (main app only)
 
void _process_env ()
 Get envname options if not yet passed. Runs on all subcommands.
 
void _process_callbacks ()
 Process callbacks. Runs on all subcommands.
 
void _process_help_flags (bool trigger_help=false, bool trigger_all_help=false) const
 
void _process_requirements ()
 Verify required options and cross requirements. Subcommands too (only if selected).
 
void _process ()
 Process callbacks and such.
 
void _process_extras ()
 Throw an error if anything is left over and should not be.
 
void _process_extras (std::vector< std::string > &args)
 
void increment_parsed ()
 Internal function to recursively increment the parsed counter on the current app as well unnamed subcommands.
 
void _parse (std::vector< std::string > &args)
 Internal parse function.
 
void _parse (std::vector< std::string > &&args)
 Internal parse function.
 
void _parse_config (std::vector< ConfigItem > &args)
 
bool _parse_single_config (const ConfigItem &item, std::size_t level=0)
 Fill in a single config option.
 
bool _parse_single (std::vector< std::string > &args, bool &positional_only)
 
std::size_t _count_remaining_positionals (bool required_only=false) const
 Count the required remaining positional arguments.
 
bool _has_remaining_positionals () const
 Count the required remaining positional arguments.
 
bool _parse_positional (std::vector< std::string > &args, bool haltOnSubcommand)
 
App_find_subcommand (const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
 
bool _parse_subcommand (std::vector< std::string > &args)
 
bool _parse_arg (std::vector< std::string > &args, detail::Classifier current_type)
 
void _trigger_pre_parse (std::size_t remaining_args)
 Trigger the pre_parse callback if needed.
 
App_get_fallthrough_parent ()
 Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
 
const std::string & _compare_subcommand_names (const App &subcom, const App &base) const
 Helper function to run through all possible comparisons of subcommand names to check there is no overlap.
 
void _move_to_missing (detail::Classifier val_type, const std::string &val)
 Helper function to place extra values in the most appropriate position.
 
- Protected Attributes inherited from CLI::App
std::string name_ {}
 Subcommand name or program name (from parser if name is empty)
 
std::string description_ {}
 Description of the current program/subcommand.
 
bool allow_extras_ {false}
 If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
 
config_extras_mode allow_config_extras_ {config_extras_mode::ignore}
 
bool prefix_command_ {false}
 If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
 
bool has_automatic_name_ {false}
 If set to true the name was automatically generated from the command line vs a user set name.
 
bool required_ {false}
 If set to true the subcommand is required to be processed and used, ignored for main app.
 
bool disabled_ {false}
 If set to true the subcommand is disabled and cannot be used, ignored for main app.
 
bool pre_parse_called_ {false}
 Flag indicating that the pre_parse_callback has been triggered.
 
bool immediate_callback_ {false}
 
std::function< void(std::size_t)> pre_parse_callback_ {}
 This is a function that runs prior to the start of parsing.
 
std::function< void()> parse_complete_callback_ {}
 This is a function that runs when parsing has finished.
 
std::function< void()> final_callback_ {}
 This is a function that runs when all processing has completed.
 
OptionDefaults option_defaults_ {}
 The default values for options, customizable and changeable INHERITABLE.
 
std::vector< Option_poptions_ {}
 The list of options, stored locally.
 
Optionconfig_ptr_ {nullptr}
 Pointer to the config option.
 
std::shared_ptr< Configconfig_formatter_ {new ConfigINI()}
 This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
 
std::vector< App_psubcommands_ {}
 Storage for subcommand list.
 
bool ignore_case_ {false}
 If true, the program name is not case sensitive INHERITABLE.
 
bool ignore_underscore_ {false}
 If true, the program should ignore underscores INHERITABLE.
 
bool fallthrough_ {false}
 Allow subcommand fallthrough, so that parent commands can collect commands after subcommand. INHERITABLE.
 
bool allow_windows_style_options_
 Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise. INHERITABLE.
 
bool positionals_at_end_ {false}
 specify that positional arguments come at the end of the argument sequence not inheritable
 
startup_mode default_startup {startup_mode::stable}
 
bool configurable_ {false}
 if set to true the subcommand can be triggered via configuration files INHERITABLE
 
bool validate_positionals_ {false}
 If set to true positional options are validated before assigning INHERITABLE.
 
Appparent_ {nullptr}
 A pointer to the parent if this is a subcommand.
 
std::size_t parsed_ {0}
 Counts the number of times this command/subcommand was parsed.
 
std::size_t require_subcommand_min_ {0}
 Minimum required subcommands (not inheritable!)
 
std::size_t require_subcommand_max_ {0}
 Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
 
std::size_t require_option_min_ {0}
 Minimum required options (not inheritable!)
 
std::size_t require_option_max_ {0}
 Max number of options allowed. 0 is unlimited (not inheritable)
 
std::string group_ {"Subcommands"}
 The group membership INHERITABLE.
 
std::vector< std::string > aliases_ {}
 Alias names for the subcommand.
 
missing_t missing_ {}
 
std::vector< Option * > parse_order_ {}
 This is a list of pointers to options with the original parse order.
 
std::vector< App * > parsed_subcommands_ {}
 This is a list of the subcommands collected, in order.
 
std::set< App * > exclude_subcommands_ {}
 this is a list of subcommands that are exclusionary to this one
 
std::set< Option * > exclude_options_ {}
 
std::set< App * > need_subcommands_ {}
 
std::set< Option * > need_options_ {}
 
std::string footer_ {}
 Footer to put after all options in the help output INHERITABLE.
 
std::function< std::string()> footer_callback_ {}
 This is a function that generates a footer to put after all other options in help output.
 
Optionhelp_ptr_ {nullptr}
 A pointer to the help flag if there is one INHERITABLE.
 
Optionhelp_all_ptr_ {nullptr}
 A pointer to the help all flag if there is one INHERITABLE.
 
std::shared_ptr< FormatterBaseformatter_ {new Formatter()}
 This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
 
std::function< std::string(const App *, const Error &e)> failure_message_ {FailureMessage::simple}
 The error message printing function INHERITABLE.
 

Detailed Description

Definition at line 7418 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ Option_group()

CLI::Option_group::Option_group ( std::string group_description,
std::string group_name,
App * parent )
inline

Definition at line 7420 of file CLI11.hpp.

7421 : App(std::move(group_description), "", parent) {
7422 group(group_name);
7423 // option groups should have automatic fallthrough
7424 }
App * group(std::string group_name)
Changes the group membership.
Definition CLI11.hpp:5664
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition CLI11.hpp:4803
Here is the call graph for this function:

Member Function Documentation

◆ add_option() [1/5]

Option * CLI::Option_group::add_option ( Option * opt)
inline

Definition at line 7427 of file CLI11.hpp.

7427 {
7428 if(get_parent() == nullptr) {
7429 throw OptionNotFound("Unable to locate the specified option");
7430 }
7431 get_parent()->_move_option(opt, this);
7432 return opt;
7433 }
App * get_parent()
Get the parent of this subcommand (or nullptr if master app)
Definition CLI11.hpp:6258
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
Definition CLI11.hpp:7377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_option() [2/5]

Option * CLI::App::add_option ( std::string option_name)
inline

Definition at line 5190 of file CLI11.hpp.

5190 {
5191 return add_option(option_name, CLI::callback_t(), std::string{}, false);
5192 }
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition CLI11.hpp:7427
std::function< bool(const results_t &)> callback_t
callback function definition
Definition CLI11.hpp:3329

◆ add_option() [3/5]

template<typename AssignTo , typename ConvertTo = AssignTo, enable_if_t<!std::is_const< ConvertTo >::value, detail::enabler > = detail::dummy>
Option * CLI::App::add_option ( std::string option_name,
AssignTo & variable,
std::string option_description = "",
bool defaulted = false )
inline
Parameters
variableThe variable to set

Definition at line 5144 of file CLI11.hpp.

5147 {
5148
5149 auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
5151 };
5152
5153 Option *opt = add_option(option_name, fun, option_description, defaulted, [&variable]() {
5155 });
5157 // these must be actual lvalues since (std::max) sometimes is defined in terms of references and references
5158 // to structs used in the evaluation can be temporary so that would cause issues.
5161 opt->type_size((std::max)(Tcount, XCcount));
5164 return opt;
5165 }
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition CLI11.hpp:4320
Option * expected(int value)
Set the number of expected arguments.
Definition CLI11.hpp:3668
Option * run_callback_for_default(bool value=true)
Definition CLI11.hpp:3719
Option * type_size(int option_type_size)
Set a custom option size.
Definition CLI11.hpp:4326
constexpr const char * type_name()
Print name for enumeration types.
Definition CLI11.hpp:1299
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition CLI11.hpp:1098
bool lexical_conversion(const std::vector< std ::string > &strings, T &output)
Conversion for tuples.
Definition CLI11.hpp:1759
std::vector< std::string > results_t
Definition CLI11.hpp:3327
static const int value
Definition CLI11.hpp:1149
static const int value
Definition CLI11.hpp:1128

◆ add_option() [4/5]

Option * CLI::App::add_option ( std::string option_name,
callback_t option_callback,
std::string option_description = "",
bool defaulted = false,
std::function< std::string()> func = {} )
inline

Add an option, will automatically understand the type for common types.

To use, create a variable with the expected type, and pass it in after the name. After start is called, you can use count to see if the value was passed, and the value will be initialized properly. Numbers, vectors, and strings are supported.

->required(), ->default, and the validators are options, The positional options take an optional number of arguments.

For example,

std::string filename;
program.add_option("filename", filename, "description of filename");

Definition at line 5099 of file CLI11.hpp.

5103 {}) {
5104 Option myopt{option_name, option_description, option_callback, this};
5105
5106 if(std::find_if(std::begin(options_), std::end(options_), [&myopt](const Option_p &v) {
5107 return *v == myopt;
5108 }) == std::end(options_)) {
5109 options_.emplace_back();
5110 Option_p &option = options_.back();
5111 option.reset(new Option(option_name, option_description, option_callback, this));
5112
5113 // Set the default string capture function
5114 option->default_function(func);
5115
5116 // For compatibility with CLI11 1.7 and before, capture the default string here
5117 if(defaulted)
5118 option->capture_default_str();
5119
5120 // Transfer defaults to the new option
5122
5123 // Don't bother to capture if we already did
5124 if(!defaulted && option->get_always_capture_default())
5125 option->capture_default_str();
5126
5127 return option.get();
5128 }
5129 // we know something matches now find what it is so we can produce more error information
5130 for(auto &opt : options_) {
5131 auto &matchname = opt->matching_name(myopt);
5132 if(!matchname.empty()) {
5133 throw(OptionAlreadyAdded("added option matched existing option name: " + matchname));
5134 }
5135 }
5136 // this line should not be reached the above loop should trigger the throw
5137 throw(OptionAlreadyAdded("added option matched existing option name")); // LCOV_EXCL_LINE
5138 }
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition CLI11.hpp:4669
std::vector< Option_p > options_
The list of options, stored locally.
Definition CLI11.hpp:4672
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition CLI11.hpp:3378
std::unique_ptr< Option > Option_p
Definition CLI11.hpp:3334
yh_option option
Definition yubihsm.h:685

◆ add_option() [5/5]

template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Option * CLI::App::add_option ( std::string option_name,
T & option_description )
inline

Definition at line 5198 of file CLI11.hpp.

5198 {
5199 return add_option(option_name, CLI::callback_t(), option_description, false);
5200 }

◆ add_options() [1/2]

void CLI::Option_group::add_options ( Option * opt)
inline

Definition at line 7435 of file CLI11.hpp.

7435{ add_option(opt); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_options() [2/2]

template<typename... Args>
void CLI::Option_group::add_options ( Option * opt,
Args... args )
inline

Definition at line 7437 of file CLI11.hpp.

7437 {
7438 add_option(opt);
7439 add_options(args...);
7440 }
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition CLI11.hpp:7435
Here is the call graph for this function:

◆ add_subcommand() [1/3]

App * CLI::Option_group::add_subcommand ( App * subcom)
inline

Definition at line 7443 of file CLI11.hpp.

7443 {
7444 App_p subc = subcom->get_parent()->get_subcommand_ptr(subcom);
7445 subc->get_parent()->remove_subcommand(subcom);
7446 add_subcommand(std::move(subc));
7447 return subcom;
7448 }
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition CLI11.hpp:7443
std::shared_ptr< App > App_p
Definition CLI11.hpp:4607
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_subcommand() [2/3]

App * CLI::App::add_subcommand ( CLI::App_p subcom)
inline

Definition at line 5547 of file CLI11.hpp.

5547 {
5548 if(!subcom)
5549 throw IncorrectConstruction("passed App is not valid");
5550 auto ckapp = (name_.empty() && parent_ != nullptr) ? _get_fallthrough_parent() : this;
5551 auto &mstrg = _compare_subcommand_names(*subcom, *ckapp);
5552 if(!mstrg.empty()) {
5553 throw(OptionAlreadyAdded("subcommand name or alias matches existing subcommand: " + mstrg));
5554 }
5555 subcom->parent_ = this;
5556 subcommands_.push_back(std::move(subcom));
5557 return subcommands_.back().get();
5558 }
App * _get_fallthrough_parent()
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
Definition CLI11.hpp:7297
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition CLI11.hpp:4733
App * parent_
A pointer to the parent if this is a subcommand.
Definition CLI11.hpp:4767
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition CLI11.hpp:4625
const std::string & _compare_subcommand_names(const App &subcom, const App &base) const
Helper function to run through all possible comparisons of subcommand names to check there is no over...
Definition CLI11.hpp:7309

◆ add_subcommand() [3/3]

App * CLI::App::add_subcommand ( std::string subcommand_name = "",
std::string subcommand_description = "" )
inline

Definition at line 5538 of file CLI11.hpp.

5538 {
5539 if(!subcommand_name.empty() && !detail::valid_name_string(subcommand_name)) {
5540 throw IncorrectConstruction("subcommand name is not valid");
5541 }
5542 CLI::App_p subcom = std::shared_ptr<App>(new App(std::move(subcommand_description), subcommand_name, this));
5543 return add_subcommand(std::move(subcom));
5544 }
bool valid_name_string(const std::string &str)
Verify an option name.
Definition CLI11.hpp:321

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