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

Creates a command line program, with very few defaults. More...

#include <CLI11.hpp>

Inheritance diagram for CLI::App:
Collaboration diagram for CLI::App:

Public Member Functions

void _move_option (Option *opt, App *app)
 function that could be used by subclasses of App to shift options around into subcommands
 
Basic
 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.
 
Subcommmands
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
 
Extras for subclassing
virtual void pre_callback ()
 
Post parsing
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.
 
Getters
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.
 

Protected Member Functions

 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

Basics
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.
 
Options
OptionDefaults option_defaults_ {}
 The default values for options, customizable and changeable INHERITABLE.
 
std::vector< Option_poptions_ {}
 The list of options, stored locally.
 
Config
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)
 

Subcommands

enum class  startup_mode : char { stable , enabled , disabled }
 
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.
 

Parsing

using missing_t = std::vector<std::pair<detail::Classifier, std::string>>
 
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_ {}
 
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.
 

Help

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.
 
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
 

Adding options

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
 

Detailed Description

To use, create a new Program() instance with argc, argv, and a help description. The templated add_option methods make it easy to prepare options. Remember to call .start before starting your program, so that the options can be evaluated and the help option doesn't accidentally run your program.

Definition at line 4614 of file CLI11.hpp.

Member Typedef Documentation

◆ missing_t

using CLI::App::missing_t = std::vector<std::pair<detail::Classifier, std::string>>
protected

Definition at line 4700 of file CLI11.hpp.

Member Enumeration Documentation

◆ startup_mode

enum class CLI::App::startup_mode : char
strongprotected
Enumerator
stable 
enabled 
disabled 

Definition at line 4755 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ App() [1/3]

CLI::App::App ( std::string app_description,
std::string app_name,
App * parent )
inlineprotected

OptionDefaults

Definition at line 4803 of file CLI11.hpp.

4804 : name_(std::move(app_name)), description_(std::move(app_description)), parent_(parent) {
4805 // Inherit if not from a nullptr
4806 if(parent_ != nullptr) {
4807 if(parent_->help_ptr_ != nullptr)
4809 if(parent_->help_all_ptr_ != nullptr)
4812
4815
4816 // INHERITABLE
4833 }
4834 }
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition CLI11.hpp:4776
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition CLI11.hpp:4669
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
Definition CLI11.hpp:5203
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition CLI11.hpp:4679
config_extras_mode allow_config_extras_
Definition CLI11.hpp:4635
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
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition CLI11.hpp:4739
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition CLI11.hpp:4694
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition CLI11.hpp:4688
bool immediate_callback_
Definition CLI11.hpp:4654
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition CLI11.hpp:4761
Option * set_help_all_flag(std::string help_name="", const std::string &help_description="")
Set a help all flag, replaced the existing one if present.
Definition CLI11.hpp:5220
std::string description_
Description of the current program/subcommand.
Definition CLI11.hpp:4628
bool ignore_case_
If true, the program name is not case sensitive INHERITABLE.
Definition CLI11.hpp:4736
std::string group_
The group membership INHERITABLE.
Definition CLI11.hpp:4785
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition CLI11.hpp:4685
bool fallthrough_
Allow subcommand fallthrough, so that parent commands can collect commands after subcommand....
Definition CLI11.hpp:4742
bool prefix_command_
If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
Definition CLI11.hpp:4638
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition CLI11.hpp:4764
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition CLI11.hpp:4631
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition CLI11.hpp:4691
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition CLI11.hpp:4745
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition CLI11.hpp:4798
const std::string & get_description() const
Get the description.
Definition CLI11.hpp:4015
std::string get_name(bool positional=false, bool all_options=false) const
Gets a comma separated list of names. Will include / prefer the positional name if positional is true...
Definition CLI11.hpp:4031
Here is the call graph for this function:
Here is the caller graph for this function:

◆ App() [2/3]

CLI::App::App ( std::string app_description = "",
std::string app_name = "" )
inlineexplicit

Definition at line 4841 of file CLI11.hpp.

4842 : App(app_description, app_name, nullptr) {
4843 set_help_flag("-h,--help", "Print this help message and exit");
4844 }
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:

◆ App() [3/3]

CLI::App::App ( const App & )
delete

◆ ~App()

virtual CLI::App::~App ( )
virtualdefault

Member Function Documentation

◆ _compare_subcommand_names()

const std::string & CLI::App::_compare_subcommand_names ( const App & subcom,
const App & base ) const
inlineprotected

Definition at line 7309 of file CLI11.hpp.

7309 {
7310 static const std::string estring;
7311 if(subcom.disabled_) {
7312 return estring;
7313 }
7314 for(auto &subc : base.subcommands_) {
7315 if(subc.get() != &subcom) {
7316 if(subc->disabled_) {
7317 continue;
7318 }
7319 if(!subcom.get_name().empty()) {
7320 if(subc->check_name(subcom.get_name())) {
7321 return subcom.get_name();
7322 }
7323 }
7324 if(!subc->get_name().empty()) {
7325 if(subcom.check_name(subc->get_name())) {
7326 return subc->get_name();
7327 }
7328 }
7329 for(const auto &les : subcom.aliases_) {
7330 if(subc->check_name(les)) {
7331 return les;
7332 }
7333 }
7334 // this loop is needed in case of ignore_underscore or ignore_case on one but not the other
7335 for(const auto &les : subc->aliases_) {
7336 if(subcom.check_name(les)) {
7337 return les;
7338 }
7339 }
7340 // if the subcommand is an option group we need to check deeper
7341 if(subc->get_name().empty()) {
7342 auto &cmpres = _compare_subcommand_names(subcom, *subc);
7343 if(!cmpres.empty()) {
7344 return cmpres;
7345 }
7346 }
7347 // if the test subcommand is an option group we need to check deeper
7348 if(subcom.get_name().empty()) {
7349 auto &cmpres = _compare_subcommand_names(*subc, subcom);
7350 if(!cmpres.empty()) {
7351 return cmpres;
7352 }
7353 }
7354 }
7355 }
7356 return estring;
7357 }
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _configure()

void CLI::App::_configure ( )
inlineprotected

configure subcommands to enable parsing through the current object set the correct fallthrough and prefix for nameless subcommands and manage the automatic enable or disable makes sure parent is set correctly

Definition at line 6419 of file CLI11.hpp.

6419 {
6421 disabled_ = false;
6423 disabled_ = true;
6424 }
6425 for(const App_p &app : subcommands_) {
6426 if(app->has_automatic_name_) {
6427 app->name_.clear();
6428 }
6429 if(app->name_.empty()) {
6430 app->fallthrough_ = false; // make sure fallthrough_ is false to prevent infinite loop
6431 app->prefix_command_ = false;
6432 }
6433 // make sure the parent is set to be this object in preparation for parse
6434 app->parent_ = this;
6435 app->_configure();
6436 }
6437 }
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition CLI11.hpp:4733
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition CLI11.hpp:4647
startup_mode default_startup
Definition CLI11.hpp:4758
std::shared_ptr< App > App_p
Definition CLI11.hpp:4607
application & app()
Here is the caller graph for this function:

◆ _count_remaining_positionals()

std::size_t CLI::App::_count_remaining_positionals ( bool required_only = false) const
inlineprotected

Definition at line 6957 of file CLI11.hpp.

6957 {
6958 std::size_t retval = 0;
6959 for(const Option_p &opt : options_) {
6960 if(opt->get_positional() && (!required_only || opt->get_required())) {
6961 if(opt->get_items_expected_min() > 0 &&
6962 static_cast<int>(opt->count()) < opt->get_items_expected_min()) {
6963 retval += static_cast<std::size_t>(opt->get_items_expected_min()) - opt->count();
6964 }
6965 }
6966 }
6967 return retval;
6968 }
std::vector< Option_p > options_
The list of options, stored locally.
Definition CLI11.hpp:4672
return retval
Definition CLI11.hpp:1754
std::unique_ptr< Option > Option_p
Definition CLI11.hpp:3334
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_subcommand()

App * CLI::App::_find_subcommand ( const std::string & subc_name,
bool ignore_disabled,
bool ignore_used ) const
inlineprotectednoexcept

Locate a subcommand by name with two conditions, should disabled subcommands be ignored, and should used subcommands be ignored

Definition at line 7085 of file CLI11.hpp.

7085 {
7086 for(const App_p &com : subcommands_) {
7087 if(com->disabled_ && ignore_disabled)
7088 continue;
7089 if(com->get_name().empty()) {
7090 auto subc = com->_find_subcommand(subc_name, ignore_disabled, ignore_used);
7091 if(subc != nullptr) {
7092 return subc;
7093 }
7094 }
7095 if(com->check_name(subc_name)) {
7096 if((!*com) || !ignore_used)
7097 return com.get();
7098 }
7099 }
7100 return nullptr;
7101 }
Here is the caller graph for this function:

◆ _get_fallthrough_parent()

App * CLI::App::_get_fallthrough_parent ( )
inlineprotected

Definition at line 7297 of file CLI11.hpp.

7297 {
7298 if(parent_ == nullptr) {
7299 throw(HorribleError("No Valid parent"));
7300 }
7301 auto fallthrough_parent = parent_;
7302 while((fallthrough_parent->parent_ != nullptr) && (fallthrough_parent->get_name().empty())) {
7303 fallthrough_parent = fallthrough_parent->parent_;
7304 }
7305 return fallthrough_parent;
7306 }
Here is the caller graph for this function:

◆ _has_remaining_positionals()

bool CLI::App::_has_remaining_positionals ( ) const
inlineprotected

Definition at line 6971 of file CLI11.hpp.

6971 {
6972 for(const Option_p &opt : options_) {
6973 if(opt->get_positional() && ((static_cast<int>(opt->count()) < opt->get_items_expected_min()))) {
6974 return true;
6975 }
6976 }
6977
6978 return false;
6979 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _move_option()

void CLI::App::_move_option ( Option * opt,
App * app )
inline

Definition at line 7377 of file CLI11.hpp.

7377 {
7378 if(opt == nullptr) {
7379 throw OptionNotFound("the option is NULL");
7380 }
7381 // verify that the give app is actually a subcommand
7382 bool found = false;
7383 for(auto &subc : subcommands_) {
7384 if(app == subc.get()) {
7385 found = true;
7386 }
7387 }
7388 if(!found) {
7389 throw OptionNotFound("The Given app is not a subcommand");
7390 }
7391
7392 if((help_ptr_ == opt) || (help_all_ptr_ == opt))
7393 throw OptionAlreadyAdded("cannot move help options");
7394
7395 if(config_ptr_ == opt)
7396 throw OptionAlreadyAdded("cannot move config file options");
7397
7398 auto iterator =
7399 std::find_if(std::begin(options_), std::end(options_), [opt](const Option_p &v) { return v.get() == opt; });
7400 if(iterator != std::end(options_)) {
7401 const auto &opt_p = *iterator;
7402 if(std::find_if(std::begin(app->options_), std::end(app->options_), [&opt_p](const Option_p &v) {
7403 return (*v == *opt_p);
7404 }) == std::end(app->options_)) {
7405 // only erase after the insertion was successful
7406 app->options_.push_back(std::move(*iterator));
7407 options_.erase(iterator);
7408 } else {
7409 throw OptionAlreadyAdded("option was not located: " + opt->get_name());
7410 }
7411 } else {
7412 throw OptionNotFound("could not locate the given Option");
7413 }
7414 }
Option * config_ptr_
Pointer to the config option.
Definition CLI11.hpp:4795
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _move_to_missing()

void CLI::App::_move_to_missing ( detail::Classifier val_type,
const std::string & val )
inlineprotected

Definition at line 7359 of file CLI11.hpp.

7359 {
7360 if(allow_extras_ || subcommands_.empty()) {
7361 missing_.emplace_back(val_type, val);
7362 return;
7363 }
7364 // allow extra arguments to be places in an option group if it is allowed there
7365 for(auto &subc : subcommands_) {
7366 if(subc->name_.empty() && subc->allow_extras_) {
7367 subc->missing_.emplace_back(val_type, val);
7368 return;
7369 }
7370 }
7371 // if we haven't found any place to put them yet put them in missing
7372 missing_.emplace_back(val_type, val);
7373 }
missing_t missing_
Definition CLI11.hpp:4705
Here is the caller graph for this function:

◆ _parse() [1/2]

void CLI::App::_parse ( std::vector< std::string > && args)
inlineprotected

Definition at line 6824 of file CLI11.hpp.

6824 {
6825 // this can only be called by the top level in which case parent == nullptr by definition
6826 // operation is simplified
6828 _trigger_pre_parse(args.size());
6829 bool positional_only = false;
6830
6831 while(!args.empty()) {
6832 _parse_single(args, positional_only);
6833 }
6834 _process();
6835
6836 // Throw error if any items are left over (depending on settings)
6838 }
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition CLI11.hpp:6914
void _process()
Process callbacks and such.
Definition CLI11.hpp:6746
void _process_extras()
Throw an error if anything is left over and should not be.
Definition CLI11.hpp:6755
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition CLI11.hpp:7278
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition CLI11.hpp:6787
Here is the call graph for this function:

◆ _parse() [2/2]

void CLI::App::_parse ( std::vector< std::string > & args)
inlineprotected

Definition at line 6795 of file CLI11.hpp.

6795 {
6797 _trigger_pre_parse(args.size());
6798 bool positional_only = false;
6799
6800 while(!args.empty()) {
6801 if(!_parse_single(args, positional_only)) {
6802 break;
6803 }
6804 }
6805
6806 if(parent_ == nullptr) {
6807 _process();
6808
6809 // Throw error if any items are left over (depending on settings)
6810 _process_extras(args);
6811
6812 // Convert missing (pairs) to extras (string only) ready for processing in another app
6813 args = remaining_for_passthrough(false);
6814 } else if(parse_complete_callback_) {
6815 _process_env();
6819 run_callback();
6820 }
6821 }
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition CLI11.hpp:6537
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
Definition CLI11.hpp:6597
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition CLI11.hpp:6620
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.
Definition CLI11.hpp:6352
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition CLI11.hpp:4660
void _process_callbacks()
Process callbacks. Runs on all subcommands.
Definition CLI11.hpp:6570
void run_callback(bool final_mode=false)
Internal function to run (App) callback, bottom up.
Definition CLI11.hpp:6439
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_arg()

bool CLI::App::_parse_arg ( std::vector< std::string > & args,
detail::Classifier current_type )
inlineprotected

Parse a short (false) or long (true) argument, must be at the top of the list return true if the argument was processed or false if nothing was done

Definition at line 7133 of file CLI11.hpp.

7133 {
7134
7135 std::string current = args.back();
7136
7137 std::string arg_name;
7138 std::string value;
7139 std::string rest;
7140
7141 switch(current_type) {
7143 if(!detail::split_long(current, arg_name, value))
7144 throw HorribleError("Long parsed but missing (you should not see this):" + args.back());
7145 break;
7147 if(!detail::split_short(current, arg_name, rest))
7148 throw HorribleError("Short parsed but missing! You should not see this");
7149 break;
7151 if(!detail::split_windows_style(current, arg_name, value))
7152 throw HorribleError("windows option parsed but missing! You should not see this");
7153 break;
7158 default:
7159 throw HorribleError("parsing got called with invalid option! You should not see this");
7160 }
7161
7162 auto op_ptr =
7163 std::find_if(std::begin(options_), std::end(options_), [arg_name, current_type](const Option_p &opt) {
7164 if(current_type == detail::Classifier::LONG)
7165 return opt->check_lname(arg_name);
7166 if(current_type == detail::Classifier::SHORT)
7167 return opt->check_sname(arg_name);
7168 // this will only get called for detail::Classifier::WINDOWS
7169 return opt->check_lname(arg_name) || opt->check_sname(arg_name);
7170 });
7171
7172 // Option not found
7173 if(op_ptr == std::end(options_)) {
7174 for(auto &subc : subcommands_) {
7175 if(subc->name_.empty() && !subc->disabled_) {
7176 if(subc->_parse_arg(args, current_type)) {
7177 if(!subc->pre_parse_called_) {
7178 subc->_trigger_pre_parse(args.size());
7179 }
7180 return true;
7181 }
7182 }
7183 }
7184 // If a subcommand, try the master command
7185 if(parent_ != nullptr && fallthrough_)
7186 return _get_fallthrough_parent()->_parse_arg(args, current_type);
7187 // don't capture missing if this is a nameless subcommand
7188 if(parent_ != nullptr && name_.empty()) {
7189 return false;
7190 }
7191 // Otherwise, add to missing
7192 args.pop_back();
7193 _move_to_missing(current_type, current);
7194 return true;
7195 }
7196
7197 args.pop_back();
7198
7199 // Get a reference to the pointer to make syntax bearable
7200 Option_p &op = *op_ptr;
7201
7202 int min_num = (std::min)(op->get_type_size_min(), op->get_items_expected_min());
7203 int max_num = op->get_items_expected_max();
7204
7205 // Make sure we always eat the minimum for unlimited vectors
7206 int collected = 0; // total number of arguments collected
7207 int result_count = 0; // local variable for number of results in a single arg string
7208 // deal with purely flag like things
7209 if(max_num == 0) {
7210 auto res = op->get_flag_value(arg_name, value);
7211 op->add_result(res);
7212 parse_order_.push_back(op.get());
7213 } else if(!value.empty()) { // --this=value
7214 op->add_result(value, result_count);
7215 parse_order_.push_back(op.get());
7216 collected += result_count;
7217 // -Trest
7218 } else if(!rest.empty()) {
7219 op->add_result(rest, result_count);
7220 parse_order_.push_back(op.get());
7221 rest = "";
7222 collected += result_count;
7223 }
7224
7225 // gather the minimum number of arguments
7226 while(min_num > collected && !args.empty()) {
7227 std::string current_ = args.back();
7228 args.pop_back();
7229 op->add_result(current_, result_count);
7230 parse_order_.push_back(op.get());
7231 collected += result_count;
7232 }
7233
7234 if(min_num > collected) { // if we have run out of arguments and the minimum was not met
7235 throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
7236 }
7237
7238 if(max_num > collected || op->get_allow_extra_args()) { // we allow optional arguments
7239 auto remreqpos = _count_remaining_positionals(true);
7240 // we have met the minimum now optionally check up to the maximum
7241 while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
7242 _recognize(args.back(), false) == detail::Classifier::NONE) {
7243 // If any required positionals remain, don't keep eating
7244 if(remreqpos >= args.size()) {
7245 break;
7246 }
7247
7248 op->add_result(args.back(), result_count);
7249 parse_order_.push_back(op.get());
7250 args.pop_back();
7251 collected += result_count;
7252 }
7253
7254 // Allow -- to end an unlimited list and "eat" it
7255 if(!args.empty() && _recognize(args.back()) == detail::Classifier::POSITIONAL_MARK)
7256 args.pop_back();
7257 // optional flag that didn't receive anything now get the default value
7258 if(min_num == 0 && max_num > 0 && collected == 0) {
7259 auto res = op->get_flag_value(arg_name, std::string{});
7260 op->add_result(res);
7261 parse_order_.push_back(op.get());
7262 }
7263 }
7264
7265 // if we only partially completed a type then add an empty string for later processing
7266 if(min_num > 0 && op->get_type_size_max() != min_num && collected % op->get_type_size_max() != 0) {
7267 op->add_result(std::string{});
7268 }
7269
7270 if(!rest.empty()) {
7271 rest = "-" + rest;
7272 args.push_back(rest);
7273 }
7274 return true;
7275 }
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::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition CLI11.hpp:6957
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type)
Definition CLI11.hpp:7133
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition CLI11.hpp:4708
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.
Definition CLI11.hpp:6479
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
Definition CLI11.hpp:7359
bool split_long(const std::string &current, std::string &name, std::string &value)
Definition CLI11.hpp:1847
bool split_short(const std::string &current, std::string &name, std::string &rest)
Definition CLI11.hpp:1837
bool split_windows_style(const std::string &current, std::string &name, std::string &value)
Definition CLI11.hpp:1863
#define value
Definition pkcs11.h:157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_config()

void CLI::App::_parse_config ( std::vector< ConfigItem > & args)
inlineprotected

Parse one config param, return false if not found in any subcommand, remove if it is

If this has more than one dot.separated.name, go into the subcommand matching it Returns true if it managed to find the option, if false you'll need to remove the arg manually.

Definition at line 6844 of file CLI11.hpp.

6844 {
6845 for(ConfigItem item : args) {
6847 throw ConfigError::Extras(item.fullname());
6848 }
6849 }
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition CLI11.hpp:6852
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_positional()

bool CLI::App::_parse_positional ( std::vector< std::string > & args,
bool haltOnSubcommand )
inlineprotected

Parse a positional, go up the tree to check

Parameters
haltOnSubcommandif set to true the operation will not process subcommands merely return false Return true if the positional was used false otherwise

Try to find a local subcommand that is repeated

now try one last gasp at subcommands that have been executed before, go to root app and try to find a subcommand in a broader way, if one exists let the parent deal with it

If this is an option group don't deal with it

We are out of other options this goes to missing

Definition at line 6984 of file CLI11.hpp.

6984 {
6985
6986 const std::string &positional = args.back();
6987
6989 // deal with the case of required arguments at the end which should take precedence over other arguments
6990 auto arg_rem = args.size();
6991 auto remreq = _count_remaining_positionals(true);
6992 if(arg_rem <= remreq) {
6993 for(const Option_p &opt : options_) {
6994 if(opt->get_positional() && opt->required_) {
6995 if(static_cast<int>(opt->count()) < opt->get_items_expected_min()) {
6997 std::string pos = positional;
6998 pos = opt->_validate(pos, 0);
6999 if(!pos.empty()) {
7000 continue;
7001 }
7002 }
7003 opt->add_result(positional);
7004 parse_order_.push_back(opt.get());
7005 args.pop_back();
7006 return true;
7007 }
7008 }
7009 }
7010 }
7011 }
7012 for(const Option_p &opt : options_) {
7013 // Eat options, one by one, until done
7014 if(opt->get_positional() &&
7015 (static_cast<int>(opt->count()) < opt->get_items_expected_min() || opt->get_allow_extra_args())) {
7017 std::string pos = positional;
7018 pos = opt->_validate(pos, 0);
7019 if(!pos.empty()) {
7020 continue;
7021 }
7022 }
7023 opt->add_result(positional);
7024 parse_order_.push_back(opt.get());
7025 args.pop_back();
7026 return true;
7027 }
7028 }
7029
7030 for(auto &subc : subcommands_) {
7031 if((subc->name_.empty()) && (!subc->disabled_)) {
7032 if(subc->_parse_positional(args, false)) {
7033 if(!subc->pre_parse_called_) {
7034 subc->_trigger_pre_parse(args.size());
7035 }
7036 return true;
7037 }
7038 }
7039 }
7040 // let the parent deal with it if possible
7041 if(parent_ != nullptr && fallthrough_)
7042 return _get_fallthrough_parent()->_parse_positional(args, static_cast<bool>(parse_complete_callback_));
7043
7045 auto com = _find_subcommand(args.back(), true, false);
7046 if(com != nullptr && (require_subcommand_max_ == 0 || require_subcommand_max_ > parsed_subcommands_.size())) {
7047 if(haltOnSubcommand) {
7048 return false;
7049 }
7050 args.pop_back();
7051 com->_parse(args);
7052 return true;
7053 }
7056 auto parent_app = (parent_ != nullptr) ? _get_fallthrough_parent() : this;
7057 com = parent_app->_find_subcommand(args.back(), true, false);
7058 if(com != nullptr && (com->parent_->require_subcommand_max_ == 0 ||
7059 com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) {
7060 return false;
7061 }
7062
7064 throw CLI::ExtrasError(name_, args);
7065 }
7067 if(parent_ != nullptr && name_.empty()) {
7068 return false;
7069 }
7072 args.pop_back();
7073 if(prefix_command_) {
7074 while(!args.empty()) {
7076 args.pop_back();
7077 }
7078 }
7079
7080 return true;
7081 }
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition CLI11.hpp:6984
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition CLI11.hpp:4711
App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition CLI11.hpp:7085
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition CLI11.hpp:4753
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_single()

bool CLI::App::_parse_single ( std::vector< std::string > & args,
bool & positional_only )
inlineprotected

Parse "one" argument (some may eat more than one), delegate to parent if fails, add to missing if missing from master return false if the parse has failed and needs to return to parent

Definition at line 6914 of file CLI11.hpp.

6914 {
6915 bool retval = true;
6916 detail::Classifier classifier = positional_only ? detail::Classifier::NONE : _recognize(args.back());
6917 switch(classifier) {
6919 args.pop_back();
6920 positional_only = true;
6921 if((!_has_remaining_positionals()) && (parent_ != nullptr)) {
6922 retval = false;
6923 } else {
6924 _move_to_missing(classifier, "--");
6925 }
6926 break;
6928 // treat this like a positional mark if in the parent app
6929 args.pop_back();
6930 retval = false;
6931 break;
6933 retval = _parse_subcommand(args);
6934 break;
6938 // If already parsed a subcommand, don't accept options_
6939 _parse_arg(args, classifier);
6940 break;
6942 // Probably a positional or something for a parent (sub)command
6943 retval = _parse_positional(args, false);
6944 if(retval && positionals_at_end_) {
6945 positional_only = true;
6946 }
6947 break;
6948 // LCOV_EXCL_START
6949 default:
6950 throw HorribleError("unrecognized classifier (you should not see this!)");
6951 // LCOV_EXCL_STOP
6952 }
6953 return retval;
6954 }
bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition CLI11.hpp:6971
bool _parse_subcommand(std::vector< std::string > &args)
Definition CLI11.hpp:7107
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_single_config()

bool CLI::App::_parse_single_config ( const ConfigItem & item,
std::size_t level = 0 )
inlineprotected

Definition at line 6852 of file CLI11.hpp.

6852 {
6853 if(level < item.parents.size()) {
6854 try {
6855 auto subcom = get_subcommand(item.parents.at(level));
6856 auto result = subcom->_parse_single_config(item, level + 1);
6857
6858 return result;
6859 } catch(const OptionNotFound &) {
6860 return false;
6861 }
6862 }
6863 // check for section open
6864 if(item.name == "++") {
6865 if(configurable_) {
6868 if(parent_ != nullptr) {
6869 parent_->parsed_subcommands_.push_back(this);
6870 }
6871 }
6872 return true;
6873 }
6874 // check for section close
6875 if(item.name == "--") {
6876 if(configurable_) {
6879 run_callback();
6880 }
6881 return true;
6882 }
6883 Option *op = get_option_no_throw("--" + item.name);
6884 if(op == nullptr) {
6885 // If the option was not present
6887 // Should we worry about classifying the extras properly?
6888 missing_.emplace_back(detail::Classifier::NONE, item.fullname());
6889 return false;
6890 }
6891
6892 if(!op->get_configurable())
6893 throw ConfigError::NotConfigurable(item.fullname());
6894
6895 if(op->empty()) {
6896 // Flag parsing
6897 if(op->get_expected_min() == 0) {
6898 auto res = config_formatter_->to_flag(item);
6899 res = op->get_flag_value(item.name, res);
6900
6901 op->add_result(res);
6902
6903 } else {
6904 op->add_result(item.inputs);
6905 op->run_callback();
6906 }
6907 }
6908
6909 return true;
6910 }
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
Definition CLI11.hpp:6119
App * get_subcommand(const App *subcom) const
Definition CLI11.hpp:5578
config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition CLI11.hpp:6240
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parse_subcommand()

bool CLI::App::_parse_subcommand ( std::vector< std::string > & args)
inlineprotected

Parse a subcommand, modify args and continue

Unlike the others, this one will always allow fallthrough return true if the subcommand was processed false otherwise

Definition at line 7107 of file CLI11.hpp.

7107 {
7108 if(_count_remaining_positionals(/* required */ true) > 0) {
7109 _parse_positional(args, false);
7110 return true;
7111 }
7112 auto com = _find_subcommand(args.back(), true, true);
7113 if(com != nullptr) {
7114 args.pop_back();
7115 parsed_subcommands_.push_back(com);
7116 com->_parse(args);
7117 auto parent_app = com->parent_;
7118 while(parent_app != this) {
7119 parent_app->_trigger_pre_parse(args.size());
7120 parent_app->parsed_subcommands_.push_back(com);
7121 parent_app = parent_app->parent_;
7122 }
7123 return true;
7124 }
7125
7126 if(parent_ == nullptr)
7127 throw HorribleError("Subcommand " + args.back() + " missing");
7128 return false;
7129 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process()

void CLI::App::_process ( )
inlineprotected

Definition at line 6746 of file CLI11.hpp.

6746 {
6748 _process_env();
6752 }
void _process_config_file()
Read and process a configuration file (main app only)
Definition CLI11.hpp:6506
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_callbacks()

void CLI::App::_process_callbacks ( )
inlineprotected

Definition at line 6570 of file CLI11.hpp.

6570 {
6571
6572 for(App_p &sub : subcommands_) {
6573 // process the priority option_groups first
6574 if(sub->get_name().empty() && sub->parse_complete_callback_) {
6575 if(sub->count_all() > 0) {
6576 sub->_process_callbacks();
6577 sub->run_callback();
6578 }
6579 }
6580 }
6581
6582 for(const Option_p &opt : options_) {
6583 if(opt->count() > 0 && !opt->get_callback_run()) {
6584 opt->run_callback();
6585 }
6586 }
6587 for(App_p &sub : subcommands_) {
6588 if(!sub->parse_complete_callback_) {
6589 sub->_process_callbacks();
6590 }
6591 }
6592 }
void sub(const Operand &op, uint32 imm)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_config_file()

void CLI::App::_process_config_file ( )
inlineprotected

Definition at line 6506 of file CLI11.hpp.

6506 {
6507 if(config_ptr_ != nullptr) {
6508 bool config_required = config_ptr_->get_required();
6509 bool file_given = config_ptr_->count() > 0;
6510 auto config_file = config_ptr_->as<std::string>();
6511 if(config_file.empty()) {
6512 if(config_required) {
6513 throw FileError::Missing("no specified config file");
6514 }
6515 return;
6516 }
6517
6518 auto path_result = detail::check_path(config_file.c_str());
6519 if(path_result == detail::path_type::file) {
6520 try {
6521 std::vector<ConfigItem> values = config_formatter_->from_file(config_file);
6522 _parse_config(values);
6523 if(!file_given) {
6524 config_ptr_->add_result(config_file);
6525 }
6526 } catch(const FileError &) {
6527 if(config_required || file_given)
6528 throw;
6529 }
6530 } else if(config_required || file_given) {
6531 throw FileError::Missing(config_file);
6532 }
6533 }
6534 }
void _parse_config(std::vector< ConfigItem > &args)
Definition CLI11.hpp:6844
bool get_required() const
True if this is a required option.
Definition CLI11.hpp:3419
std::size_t count() const
Count the total number of times an option was passed.
Definition CLI11.hpp:3649
Option * add_result(std::string s)
Puts a result at the end.
Definition CLI11.hpp:4223
T as() const
Return the results as the specified type.
Definition CLI11.hpp:4300
path_type check_path(const char *file) noexcept
get the type of the path from a file name
Definition CLI11.hpp:2336
GeneratorWrapper< T > values(std::initializer_list< T > values)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_env()

void CLI::App::_process_env ( )
inlineprotected

Definition at line 6537 of file CLI11.hpp.

6537 {
6538 for(const Option_p &opt : options_) {
6539 if(opt->count() == 0 && !opt->envname_.empty()) {
6540 char *buffer = nullptr;
6541 std::string ename_string;
6542
6543#ifdef _MSC_VER
6544 // Windows version
6545 std::size_t sz = 0;
6546 if(_dupenv_s(&buffer, &sz, opt->envname_.c_str()) == 0 && buffer != nullptr) {
6547 ename_string = std::string(buffer);
6548 free(buffer);
6549 }
6550#else
6551 // This also works on Windows, but gives a warning
6552 buffer = std::getenv(opt->envname_.c_str());
6553 if(buffer != nullptr)
6554 ename_string = std::string(buffer);
6555#endif
6556
6557 if(!ename_string.empty()) {
6558 opt->add_result(ename_string);
6559 }
6560 }
6561 }
6562
6563 for(App_p &sub : subcommands_) {
6564 if(sub->get_name().empty() || !sub->parse_complete_callback_)
6565 sub->_process_env();
6566 }
6567 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_extras() [1/2]

void CLI::App::_process_extras ( )
inlineprotected

Definition at line 6755 of file CLI11.hpp.

6755 {
6756 if(!(allow_extras_ || prefix_command_)) {
6757 std::size_t num_left_over = remaining_size();
6758 if(num_left_over > 0) {
6759 throw ExtrasError(name_, remaining(false));
6760 }
6761 }
6762
6763 for(App_p &sub : subcommands_) {
6764 if(sub->count() > 0)
6765 sub->_process_extras();
6766 }
6767 }
std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition CLI11.hpp:6359
std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition CLI11.hpp:6325
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_extras() [2/2]

void CLI::App::_process_extras ( std::vector< std::string > & args)
inlineprotected

Throw an error if anything is left over and should not be. Modifies the args to fill in the missing items before throwing.

Definition at line 6771 of file CLI11.hpp.

6771 {
6772 if(!(allow_extras_ || prefix_command_)) {
6773 std::size_t num_left_over = remaining_size();
6774 if(num_left_over > 0) {
6775 args = remaining(false);
6776 throw ExtrasError(name_, args);
6777 }
6778 }
6779
6780 for(App_p &sub : subcommands_) {
6781 if(sub->count() > 0)
6782 sub->_process_extras(args);
6783 }
6784 }
Here is the call graph for this function:

◆ _process_help_flags()

void CLI::App::_process_help_flags ( bool trigger_help = false,
bool trigger_all_help = false ) const
inlineprotected

Run help flag processing if any are found.

The flags allow recursive calls to remember if there was a help flag on a parent.

Definition at line 6597 of file CLI11.hpp.

6597 {
6598 const Option *help_ptr = get_help_ptr();
6599 const Option *help_all_ptr = get_help_all_ptr();
6600
6601 if(help_ptr != nullptr && help_ptr->count() > 0)
6602 trigger_help = true;
6603 if(help_all_ptr != nullptr && help_all_ptr->count() > 0)
6604 trigger_all_help = true;
6605
6606 // If there were parsed subcommands, call those. First subcommand wins if there are multiple ones.
6607 if(!parsed_subcommands_.empty()) {
6608 for(const App *sub : parsed_subcommands_)
6609 sub->_process_help_flags(trigger_help, trigger_all_help);
6610
6611 // Only the final subcommand should call for help. All help wins over help.
6612 } else if(trigger_all_help) {
6613 throw CallForAllHelp();
6614 } else if(trigger_help) {
6615 throw CallForHelp();
6616 }
6617 }
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition CLI11.hpp:6249
Option * get_help_ptr()
Get a pointer to the help flag.
Definition CLI11.hpp:6243
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_requirements()

void CLI::App::_process_requirements ( )
inlineprotected

Definition at line 6620 of file CLI11.hpp.

6620 {
6621 // check excludes
6622 bool excluded{false};
6623 std::string excluder;
6624 for(auto &opt : exclude_options_) {
6625 if(opt->count() > 0) {
6626 excluded = true;
6627 excluder = opt->get_name();
6628 }
6629 }
6630 for(auto &subc : exclude_subcommands_) {
6631 if(subc->count_all() > 0) {
6632 excluded = true;
6633 excluder = subc->get_display_name();
6634 }
6635 }
6636 if(excluded) {
6637 if(count_all() > 0) {
6638 throw ExcludesError(get_display_name(), excluder);
6639 }
6640 // if we are excluded but didn't receive anything, just return
6641 return;
6642 }
6643
6644 // check excludes
6645 bool missing_needed{false};
6646 std::string missing_need;
6647 for(auto &opt : need_options_) {
6648 if(opt->count() == 0) {
6649 missing_needed = true;
6650 missing_need = opt->get_name();
6651 }
6652 }
6653 for(auto &subc : need_subcommands_) {
6654 if(subc->count_all() == 0) {
6655 missing_needed = true;
6656 missing_need = subc->get_display_name();
6657 }
6658 }
6659 if(missing_needed) {
6660 if(count_all() > 0) {
6661 throw RequiresError(get_display_name(), missing_need);
6662 }
6663 // if we missing something but didn't have any options, just return
6664 return;
6665 }
6666
6667 std::size_t used_options = 0;
6668 for(const Option_p &opt : options_) {
6669
6670 if(opt->count() != 0) {
6671 ++used_options;
6672 }
6673 // Required but empty
6674 if(opt->get_required() && opt->count() == 0) {
6675 throw RequiredError(opt->get_name());
6676 }
6677 // Requires
6678 for(const Option *opt_req : opt->needs_)
6679 if(opt->count() > 0 && opt_req->count() == 0)
6680 throw RequiresError(opt->get_name(), opt_req->get_name());
6681 // Excludes
6682 for(const Option *opt_ex : opt->excludes_)
6683 if(opt->count() > 0 && opt_ex->count() != 0)
6684 throw ExcludesError(opt->get_name(), opt_ex->get_name());
6685 }
6686 // check for the required number of subcommands
6687 if(require_subcommand_min_ > 0) {
6688 auto selected_subcommands = get_subcommands();
6689 if(require_subcommand_min_ > selected_subcommands.size())
6690 throw RequiredError::Subcommand(require_subcommand_min_);
6691 }
6692
6693 // Max error cannot occur, the extra subcommand will parse as an ExtrasError or a remaining item.
6694
6695 // run this loop to check how many unnamed subcommands were actually used since they are considered options
6696 // from the perspective of an App
6697 for(App_p &sub : subcommands_) {
6698 if(sub->disabled_)
6699 continue;
6700 if(sub->name_.empty() && sub->count_all() > 0) {
6701 ++used_options;
6702 }
6703 }
6704
6705 if(require_option_min_ > used_options || (require_option_max_ > 0 && require_option_max_ < used_options)) {
6706 auto option_list = detail::join(options_, [](const Option_p &ptr) { return ptr->get_name(false, true); });
6707 if(option_list.compare(0, 10, "-h,--help,") == 0) {
6708 option_list.erase(0, 10);
6709 }
6710 auto subc_list = get_subcommands([](App *app) { return ((app->get_name().empty()) && (!app->disabled_)); });
6711 if(!subc_list.empty()) {
6712 option_list += "," + detail::join(subc_list, [](const App *app) { return app->get_display_name(); });
6713 }
6714 throw RequiredError::Option(require_option_min_, require_option_max_, used_options, option_list);
6715 }
6716
6717 // now process the requirements for subcommands if needed
6718 for(App_p &sub : subcommands_) {
6719 if(sub->disabled_)
6720 continue;
6721 if(sub->name_.empty() && sub->required_ == false) {
6722 if(sub->count_all() == 0) {
6723 if(require_option_min_ > 0 && require_option_min_ <= used_options) {
6724 continue;
6725 // if we have met the requirement and there is nothing in this option group skip checking
6726 // requirements
6727 }
6728 if(require_option_max_ > 0 && used_options >= require_option_min_) {
6729 continue;
6730 // if we have met the requirement and there is nothing in this option group skip checking
6731 // requirements
6732 }
6733 }
6734 }
6735 if(sub->count() > 0 || sub->name_.empty()) {
6736 sub->_process_requirements();
6737 }
6738
6739 if(sub->required_ && sub->count_all() == 0) {
6740 throw(CLI::RequiredError(sub->get_display_name()));
6741 }
6742 }
6743 }
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition CLI11.hpp:4779
std::size_t count_all() const
Definition CLI11.hpp:5649
std::set< Option * > exclude_options_
Definition CLI11.hpp:4718
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition CLI11.hpp:4773
std::vector< App * > get_subcommands() const
Definition CLI11.hpp:5893
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition CLI11.hpp:4782
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition CLI11.hpp:4714
std::set< Option * > need_options_
Definition CLI11.hpp:4726
std::set< App * > need_subcommands_
Definition CLI11.hpp:4722
std::string get_display_name() const
Get a display name for an app.
Definition CLI11.hpp:6276
Thrown when a required option is missing.
Definition CLI11.hpp:710
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition CLI11.hpp:196
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _recognize()

detail::Classifier CLI::App::_recognize ( const std::string & current,
bool ignore_used_subcommands = true ) const
inlineprotected

Definition at line 6479 of file CLI11.hpp.

6479 {
6480 std::string dummy1, dummy2;
6481
6482 if(current == "--")
6484 if(_valid_subcommand(current, ignore_used_subcommands))
6486 if(detail::split_long(current, dummy1, dummy2))
6488 if(detail::split_short(current, dummy1, dummy2)) {
6489 if(dummy1[0] >= '0' && dummy1[0] <= '9') {
6490 if(get_option_no_throw(std::string{'-', dummy1[0]}) == nullptr) {
6492 }
6493 }
6495 }
6496 if((allow_windows_style_options_) && (detail::split_windows_style(current, dummy1, dummy2)))
6498 if((current == "++") && !name_.empty() && parent_ != nullptr)
6501 }
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.
Definition CLI11.hpp:6465
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _trigger_pre_parse()

void CLI::App::_trigger_pre_parse ( std::size_t remaining_args)
inlineprotected

Definition at line 7278 of file CLI11.hpp.

7278 {
7279 if(!pre_parse_called_) {
7280 pre_parse_called_ = true;
7282 pre_parse_callback_(remaining_args);
7283 }
7284 } else if(immediate_callback_) {
7285 if(!name_.empty()) {
7286 auto pcnt = parsed_;
7287 auto extras = std::move(missing_);
7288 clear();
7289 parsed_ = pcnt;
7290 pre_parse_called_ = true;
7291 missing_ = std::move(extras);
7292 }
7293 }
7294 }
void clear()
Reset the parsed data.
Definition CLI11.hpp:5752
std::size_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition CLI11.hpp:4770
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition CLI11.hpp:4657
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition CLI11.hpp:4650
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _valid_subcommand()

bool CLI::App::_valid_subcommand ( const std::string & current,
bool ignore_used = true ) const
inlineprotected

Definition at line 6465 of file CLI11.hpp.

6465 {
6466 // Don't match if max has been reached - but still check parents
6468 return parent_ != nullptr && parent_->_valid_subcommand(current, ignore_used);
6469 }
6470 auto com = _find_subcommand(current, true, ignore_used);
6471 if(com != nullptr) {
6472 return true;
6473 }
6474 // Check parent if exists, else return false
6475 return parent_ != nullptr && parent_->_valid_subcommand(current, ignore_used);
6476 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _validate()

void CLI::App::_validate ( ) const
inlineprotected

Check the options to make sure there are no conflicts.

Currently checks to see if multiple positionals exist with unlimited args and checks if the min and max options are feasible

Definition at line 6380 of file CLI11.hpp.

6380 {
6381 // count the number of positional only args
6382 auto pcount = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) {
6383 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional();
6384 });
6385 if(pcount > 1) {
6386 auto pcount_req = std::count_if(std::begin(options_), std::end(options_), [](const Option_p &opt) {
6387 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional() &&
6388 opt->get_required();
6389 });
6390 if(pcount - pcount_req > 1) {
6391 throw InvalidError(name_);
6392 }
6393 }
6394
6395 std::size_t nameless_subs{0};
6396 for(const App_p &app : subcommands_) {
6397 app->_validate();
6398 if(app->get_name().empty())
6399 ++nameless_subs;
6400 }
6401
6402 if(require_option_min_ > 0) {
6403 if(require_option_max_ > 0) {
6405 throw(InvalidError("Required min options greater than required max options",
6407 }
6408 }
6409 if(require_option_min_ > (options_.size() + nameless_subs)) {
6410 throw(InvalidError("Required min options greater than number of available options",
6412 }
6413 }
6414 }
constexpr int expected_max_vector_size
Definition CLI11.hpp:176
Here is the caller graph for this function:

◆ add_complex()

template<typename T , typename XC = double>
Option * CLI::App::add_complex ( std::string option_name,
T & variable,
std::string option_description = "",
bool defaulted = false,
std::string label = "COMPLEX" )
inline

Definition at line 5425 of file CLI11.hpp.

5429 {
5430
5431 CLI::callback_t fun = [&variable](const results_t &res) {
5432 XC x, y;
5433 bool worked;
5434 if(res.size() >= 2 && !res[1].empty()) {
5435 auto str1 = res[1];
5436 if(str1.back() == 'i' || str1.back() == 'j')
5437 str1.pop_back();
5438 worked = detail::lexical_cast(res[0], x) && detail::lexical_cast(str1, y);
5439 } else {
5440 auto str1 = res.front();
5441 auto nloc = str1.find_last_of('-');
5442 if(nloc != std::string::npos && nloc > 0) {
5443 worked = detail::lexical_cast(str1.substr(0, nloc), x);
5444 str1 = str1.substr(nloc);
5445 if(str1.back() == 'i' || str1.back() == 'j')
5446 str1.pop_back();
5447 worked = worked && detail::lexical_cast(str1, y);
5448 } else {
5449 if(str1.back() == 'i' || str1.back() == 'j') {
5450 str1.pop_back();
5451 worked = detail::lexical_cast(str1, y);
5452 x = XC{0};
5453 } else {
5454 worked = detail::lexical_cast(str1, x);
5455 y = XC{0};
5456 }
5457 }
5458 }
5459 if(worked)
5460 variable = T{x, y};
5461 return worked;
5462 };
5463
5464 auto default_function = [&variable]() { return CLI::detail::checked_to_string<T, T>(variable); };
5465
5466 CLI::Option *opt =
5467 add_option(option_name, std::move(fun), std::move(option_description), defaulted, default_function);
5468
5470 return opt;
5471 }
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition CLI11.hpp:5099
CRTP * delimiter(char value='\0')
Allow in a configuration file.
Definition CLI11.hpp:3487
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition CLI11.hpp:4320
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
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition CLI11.hpp:1098
std::function< bool(const results_t &)> callback_t
callback function definition
Definition CLI11.hpp:3329
std::vector< std::string > results_t
Definition CLI11.hpp:3327
uint64_t y
Definition sha3.cpp:34
#define T(meth, val, expected)
char * label
Here is the call graph for this function:

◆ add_flag() [1/5]

Option * CLI::App::add_flag ( std::string flag_name)
inline

Definition at line 5265 of file CLI11.hpp.

5265{ return _add_flag_internal(flag_name, CLI::callback_t(), std::string{}); }
Here is the caller graph for this function:

◆ add_flag() [2/5]

template<typename T , enable_if_t<!std::is_assignable< std::function< void(int64_t)>, T >::value, detail::enabler > = detail::dummy>
Option * CLI::App::add_flag ( std::string flag_name,
std::vector< T > & flag_results,
std::string flag_description = "" )
inline
Parameters
flag_resultsA vector of values with the flag results

Definition at line 5317 of file CLI11.hpp.

5319 {
5320 CLI::callback_t fun = [&flag_results](const CLI::results_t &res) {
5321 bool retval = true;
5322 for(const auto &elem : res) {
5323 flag_results.emplace_back();
5324 retval &= detail::lexical_cast(elem, flag_results.back());
5325 }
5326 return retval;
5327 };
5328 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
5331 }
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition CLI11.hpp:3932
@ TakeAll
just get all the passed argument regardless
Here is the call graph for this function:

◆ add_flag() [3/5]

template<typename T , enable_if_t< std::is_integral< T >::value &&!is_bool< T >::value, detail::enabler > = detail::dummy>
Option * CLI::App::add_flag ( std::string flag_name,
T & flag_count,
std::string flag_description = "" )
inline

Add option for flag with integer result - defaults to allowing multiple passings, but can be forced to one if multi_option_policy(CLI::MultiOptionPolicy::Throw) is used.

Parameters
flag_countA variable holding the count

Definition at line 5281 of file CLI11.hpp.

5283 {
5284 flag_count = 0;
5285 CLI::callback_t fun = [&flag_count](const CLI::results_t &res) {
5286 try {
5287 detail::sum_flag_vector(res, flag_count);
5288 } catch(const std::invalid_argument &) {
5289 return false;
5290 }
5291 return true;
5292 };
5293 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
5295 }
void sum_flag_vector(const std::vector< std::string > &flags, T &output)
Definition CLI11.hpp:1805
Here is the call graph for this function:

◆ add_flag() [4/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_flag ( std::string flag_name,
T & flag_description )
inline

Add flag with description but with no variable assignment or callback takes a constant string, if a variable string is passed that variable will be assigned the results from the flag

Definition at line 5273 of file CLI11.hpp.

5273 {
5274 return _add_flag_internal(flag_name, CLI::callback_t(), flag_description);
5275 }

◆ add_flag() [5/5]

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>
Option * CLI::App::add_flag ( std::string flag_name,
T & flag_result,
std::string flag_description = "" )
inline

Other type version accepts all other types that are not vectors such as bool, enum, string or other classes that can be converted from a string

Parameters
flag_resultA variable holding true if passed

Definition at line 5304 of file CLI11.hpp.

5306 {
5307
5308 CLI::callback_t fun = [&flag_result](const CLI::results_t &res) {
5309 return CLI::detail::lexical_cast(res[0], flag_result);
5310 };
5311 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))->run_callback_for_default();
5312 }
Here is the call graph for this function:

◆ add_flag_callback()

Option * CLI::App::add_flag_callback ( std::string flag_name,
std::function< void(void)> function,
std::string flag_description = "" )
inline
Parameters
functionA function to call, void(void)

Definition at line 5334 of file CLI11.hpp.

5336 {
5337
5338 CLI::callback_t fun = [function](const CLI::results_t &res) {
5339 bool trigger{false};
5340 auto result = CLI::detail::lexical_cast(res[0], trigger);
5341 if(result && trigger) {
5342 function();
5343 }
5344 return result;
5345 };
5346 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
5347 }

◆ add_flag_function()

Option * CLI::App::add_flag_function ( std::string flag_name,
std::function< void(int64_t)> function,
std::string flag_description = "" )
inline
Parameters
functionA function to call, void(int)

Definition at line 5350 of file CLI11.hpp.

5352 {
5353
5354 CLI::callback_t fun = [function](const CLI::results_t &res) {
5355 int64_t flag_count = 0;
5356 detail::sum_flag_vector(res, flag_count);
5357 function(flag_count);
5358 return true;
5359 };
5360 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
5362 }
signed __int64 int64_t
Definition stdint.h:135
Here is the call graph for this function:

◆ add_mutable_set() [1/2]

template<typename T >
Option * CLI::App::add_mutable_set ( std::string option_name,
T & member,
const std::set< T > & options,
std::string option_description,
bool defaulted )
inline
Parameters
memberThe selected member of the set
optionsThe set of possibilities

Definition at line 5412 of file CLI11.hpp.

5416 {
5417
5418 Option *opt = add_option(option_name, member, std::move(option_description), defaulted);
5419 opt->check(IsMember{&options});
5420 return opt;
5421 }
Here is the call graph for this function:

◆ add_mutable_set() [2/2]

template<typename T >
Option * CLI::App::add_mutable_set ( std::string option_name,
T & member,
const std::set< T > & options,
std::string option_description = "" )
inline
Parameters
memberThe selected member of the set
optionsThe set of possibilities

Definition at line 5387 of file CLI11.hpp.

5390 {
5391
5392 Option *opt = add_option(option_name, member, std::move(option_description));
5393 opt->check(IsMember{&options});
5394 return opt;
5395 }
Here is the call graph for this function:

◆ add_option() [1/4]

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 }
Here is the call graph for this function:

◆ add_option() [2/4]

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 * expected(int value)
Set the number of expected arguments.
Definition CLI11.hpp:3668
constexpr const char * type_name()
Print name for enumeration types.
Definition CLI11.hpp:1299
bool lexical_conversion(const std::vector< std ::string > &strings, T &output)
Conversion for tuples.
Definition CLI11.hpp:1759
static const int value
Definition CLI11.hpp:1149
static const int value
Definition CLI11.hpp:1128
Here is the call graph for this function:

◆ add_option() [3/4]

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 }
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition CLI11.hpp:3378
yh_option option
Definition yubihsm.h:685

◆ add_option() [4/4]

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 }
Here is the call graph for this function:

◆ add_option_function()

template<typename T >
Option * CLI::App::add_option_function ( std::string option_name,
const std::function< void(const T &)> & func,
std::string option_description = "" )
inline
Parameters
functhe callback to execute

Definition at line 5169 of file CLI11.hpp.

5171 {
5172
5173 auto fun = [func](const CLI::results_t &res) {
5174 T variable;
5175 bool result = detail::lexical_conversion<T, T>(res, variable);
5176 if(result) {
5177 func(variable);
5178 }
5179 return result;
5180 };
5181
5182 Option *opt = add_option(option_name, std::move(fun), option_description, false);
5183 opt->type_name(detail::type_name<T>());
5184 opt->type_size(detail::type_count<T>::value);
5185 opt->expected(detail::expected_count<T>::value);
5186 return opt;
5187 }
Here is the call graph for this function:

◆ add_option_group()

template<typename T = Option_group>
T * CLI::App::add_option_group ( std::string group_name,
std::string group_description = "" )
inline

Definition at line 5524 of file CLI11.hpp.

5524 {
5525 auto option_group = std::make_shared<T>(std::move(group_description), group_name, nullptr);
5526 auto ptr = option_group.get();
5527 // move to App_p for overload resolution on older gcc versions
5528 App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
5529 add_subcommand(std::move(app_ptr));
5530 return ptr;
5531 }
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition CLI11.hpp:5538
Here is the call graph for this function:

◆ add_set() [1/2]

template<typename T >
Option * CLI::App::add_set ( std::string option_name,
T & member,
std::set< T > options,
std::string option_description,
bool defaulted )
inline
Parameters
memberThe selected member of the set
optionsThe set of possibilities

Definition at line 5399 of file CLI11.hpp.

5403 {
5404
5405 Option *opt = add_option(option_name, member, std::move(option_description), defaulted);
5406 opt->check(IsMember{options});
5407 return opt;
5408 }
Here is the call graph for this function:

◆ add_set() [2/2]

template<typename T >
Option * CLI::App::add_set ( std::string option_name,
T & member,
std::set< T > options,
std::string option_description = "" )
inline
Parameters
memberThe selected member of the set
optionsThe set of possibilities

Definition at line 5375 of file CLI11.hpp.

5378 {
5379
5380 Option *opt = add_option(option_name, member, std::move(option_description));
5381 opt->check(IsMember{options});
5382 return opt;
5383 }
Here is the call graph for this function:

◆ add_subcommand() [1/2]

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 }
Here is the call graph for this function:

◆ add_subcommand() [2/2]

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alias()

App * CLI::App::alias ( std::string app_name)
inline

Definition at line 4907 of file CLI11.hpp.

4907 {
4908 if(!detail::valid_name_string(app_name)) {
4909 throw(IncorrectConstruction("alias is not a valid name string"));
4910 }
4911
4912 if(parent_ != nullptr) {
4913 aliases_.push_back(app_name);
4915 if(!res.empty()) {
4916 aliases_.pop_back();
4917 throw(OptionAlreadyAdded("alias already matches an existing subcommand: " + app_name));
4918 }
4919 } else {
4920 aliases_.push_back(app_name);
4921 }
4922
4923 return this;
4924 }
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition CLI11.hpp:4788
Here is the call graph for this function:

◆ allow_config_extras() [1/2]

App * CLI::App::allow_config_extras ( bool allow = true)
inline

Definition at line 4986 of file CLI11.hpp.

4986 {
4987 if(allow) {
4989 allow_extras_ = true;
4990 } else {
4992 }
4993 return this;
4994 }

◆ allow_config_extras() [2/2]

App * CLI::App::allow_config_extras ( config_extras_mode mode)
inline

Definition at line 4997 of file CLI11.hpp.

4997 {
4998 allow_config_extras_ = mode;
4999 return this;
5000 }

◆ allow_extras()

App * CLI::App::allow_extras ( bool allow = true)
inline

Definition at line 4927 of file CLI11.hpp.

4927 {
4928 allow_extras_ = allow;
4929 return this;
4930 }

◆ allow_windows_style_options()

App * CLI::App::allow_windows_style_options ( bool value = true)
inline

Allow windows style options, such as /opt. First matching short or long name used. Subcommands inherit value.

Definition at line 5025 of file CLI11.hpp.

5025 {
5027 return this;
5028 }

◆ callback()

App * CLI::App::callback ( std::function< void()> app_callback)
inline

Set a callback for execution when all parsing and processing has completed

Due to a bug in c++11, it is not possible to overload on std::function (fixed in c++14 and backported to c++11 on newer compilers). Use capture by reference to get a pointer to App if needed.

Definition at line 4858 of file CLI11.hpp.

4858 {
4860 parse_complete_callback_ = std::move(app_callback);
4861 } else {
4862 final_callback_ = std::move(app_callback);
4863 }
4864 return this;
4865 }
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition CLI11.hpp:4662

◆ check_name()

bool CLI::App::check_name ( std::string name_to_check) const
inline

Definition at line 6279 of file CLI11.hpp.

6279 {
6280 std::string local_name = name_;
6281 if(ignore_underscore_) {
6282 local_name = detail::remove_underscore(name_);
6283 name_to_check = detail::remove_underscore(name_to_check);
6284 }
6285 if(ignore_case_) {
6286 local_name = detail::to_lower(name_);
6287 name_to_check = detail::to_lower(name_to_check);
6288 }
6289
6290 if(local_name == name_to_check) {
6291 return true;
6292 }
6293 for(auto les : aliases_) {
6294 if(ignore_underscore_) {
6295 les = detail::remove_underscore(les);
6296 }
6297 if(ignore_case_) {
6298 les = detail::to_lower(les);
6299 }
6300 if(les == name_to_check) {
6301 return true;
6302 }
6303 }
6304 return false;
6305 }
std::string remove_underscore(std::string str)
remove underscores from a string
Definition CLI11.hpp:344
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition CLI11.hpp:336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void CLI::App::clear ( )
inline

Definition at line 5752 of file CLI11.hpp.

5752 {
5753
5754 parsed_ = 0;
5755 pre_parse_called_ = false;
5756
5757 missing_.clear();
5758 parsed_subcommands_.clear();
5759 for(const Option_p &opt : options_) {
5760 opt->clear();
5761 }
5762 for(const App_p &subc : subcommands_) {
5763 subc->clear();
5764 }
5765 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_aliases()

App * CLI::App::clear_aliases ( )
inline

Definition at line 6270 of file CLI11.hpp.

6270 {
6271 aliases_.clear();
6272 return this;
6273 }
Here is the call graph for this function:

◆ config_formatter()

App * CLI::App::config_formatter ( std::shared_ptr< Config > fmt)
inline

Definition at line 5070 of file CLI11.hpp.

5070 {
5071 config_formatter_ = fmt;
5072 return this;
5073 }

◆ config_to_str()

std::string CLI::App::config_to_str ( bool default_also = false,
bool write_description = false ) const
inline

Produce a string that could be read in as a config of the current values of the App. Set default_also to include default arguments. Prefix will add a string to the beginning of each option.

Definition at line 6041 of file CLI11.hpp.

6041 {
6042 return config_formatter_->to_config(this, default_also, write_description, "");
6043 }

◆ configurable()

App * CLI::App::configurable ( bool value = true)
inline

Definition at line 5037 of file CLI11.hpp.

5037 {
5039 return this;
5040 }

◆ count() [1/2]

std::size_t CLI::App::count ( ) const
inline

No argument version of count counts the number of times this subcommand was passed in. The main app will return 1. Unnamed subcommands will also return 1 unless otherwise modified in a callback

Definition at line 5645 of file CLI11.hpp.

5645{ return parsed_; }

◆ count() [2/2]

std::size_t CLI::App::count ( std::string option_name) const
inline

Definition at line 5889 of file CLI11.hpp.

5889{ return get_option(option_name)->count(); }
const Option * get_option(std::string option_name) const
Get an option by name.
Definition CLI11.hpp:6157
Here is the call graph for this function:

◆ count_all()

std::size_t CLI::App::count_all ( ) const
inline

Get a count of all the arguments processed in options and subcommands, this excludes arguments which were treated as extras.

Definition at line 5649 of file CLI11.hpp.

5649 {
5650 std::size_t cnt{0};
5651 for(auto &opt : options_) {
5652 cnt += opt->count();
5653 }
5654 for(auto &sub : subcommands_) {
5655 cnt += sub->count_all();
5656 }
5657 if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called
5658 cnt += parsed_;
5659 }
5660 return cnt;
5661 }
const std::string & get_name() const
Get the name of the current app.
Definition CLI11.hpp:6264
Here is the call graph for this function:
Here is the caller graph for this function:

◆ description()

App * CLI::App::description ( std::string app_description)
inline

Definition at line 6080 of file CLI11.hpp.

6080 {
6081 description_ = std::move(app_description);
6082 return this;
6083 }

◆ disabled()

App * CLI::App::disabled ( bool disable = true)
inline

Definition at line 4939 of file CLI11.hpp.

4939 {
4940 disabled_ = disable;
4941 return this;
4942 }
Here is the caller graph for this function:

◆ disabled_by_default()

App * CLI::App::disabled_by_default ( bool disable = true)
inline

Definition at line 4945 of file CLI11.hpp.

4945 {
4946 if(disable) {
4948 } else {
4950 }
4951 return this;
4952 }
Here is the caller graph for this function:

◆ enabled_by_default()

App * CLI::App::enabled_by_default ( bool enable = true)
inline

Set the subcommand to be enabled by default, so on clear(), at the start of each parse it is enabled (not disabled)

Definition at line 4956 of file CLI11.hpp.

4956 {
4957 if(enable) {
4959 } else {
4962 }
4963 return this;
4964 }
Here is the caller graph for this function:

◆ excludes() [1/2]

App * CLI::App::excludes ( App * app)
inline

Definition at line 5949 of file CLI11.hpp.

5949 {
5950 if(app == nullptr) {
5951 throw OptionNotFound("nullptr passed");
5952 }
5953 if(app == this) {
5954 throw OptionNotFound("cannot self reference in needs");
5955 }
5956 auto res = exclude_subcommands_.insert(app);
5957 // subcommand exclusion should be symmetric
5958 if(res.second) {
5959 app->exclude_subcommands_.insert(this);
5960 }
5961 return this;
5962 }

◆ excludes() [2/2]

App * CLI::App::excludes ( Option * opt)
inline

Definition at line 5940 of file CLI11.hpp.

5940 {
5941 if(opt == nullptr) {
5942 throw OptionNotFound("nullptr passed");
5943 }
5944 exclude_options_.insert(opt);
5945 return this;
5946 }

◆ exit()

int CLI::App::exit ( const Error & e,
std::ostream & out = std::cout,
std::ostream & err = std::cerr ) const
inline

Avoid printing anything if this is a CLI::RuntimeError

Definition at line 5860 of file CLI11.hpp.

5860 {
5861
5863 if(dynamic_cast<const CLI::RuntimeError *>(&e) != nullptr)
5864 return e.get_exit_code();
5865
5866 if(dynamic_cast<const CLI::CallForHelp *>(&e) != nullptr) {
5867 out << help();
5868 return e.get_exit_code();
5869 }
5870
5871 if(dynamic_cast<const CLI::CallForAllHelp *>(&e) != nullptr) {
5872 out << help("", AppFormatMode::All);
5873 return e.get_exit_code();
5874 }
5875
5876 if(e.get_exit_code() != static_cast<int>(ExitCodes::Success)) {
5878 err << failure_message_(this, e) << std::flush;
5879 }
5880
5881 return e.get_exit_code();
5882 }
std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition CLI11.hpp:6047
Usually something like –help-all on command line.
Definition CLI11.hpp:667
-h or –help on command line
Definition CLI11.hpp:661
Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error c...
Definition CLI11.hpp:674
Here is the call graph for this function:

◆ failure_message()

void CLI::App::failure_message ( std::function< std::string(const App *, const Error &e)> function)
inline

Definition at line 5855 of file CLI11.hpp.

5855 {
5856 failure_message_ = function;
5857 }

◆ fallthrough()

App * CLI::App::fallthrough ( bool value = true)
inline

Stop subcommand fallthrough, so that parent commands cannot collect commands after subcommand. Default from parent, usually set on parent.

Definition at line 5729 of file CLI11.hpp.

5729 {
5731 return this;
5732 }

◆ final_callback()

App * CLI::App::final_callback ( std::function< void()> app_callback)
inline

Set a callback for execution when all parsing and processing has completed aliased as callback

Definition at line 4869 of file CLI11.hpp.

4869 {
4870 final_callback_ = std::move(app_callback);
4871 return this;
4872 }

◆ footer() [1/2]

App * CLI::App::footer ( std::function< std::string()> footer_function)
inline

Definition at line 6035 of file CLI11.hpp.

6035 {
6036 footer_callback_ = std::move(footer_function);
6037 return this;
6038 }
std::function< std::string()> footer_callback_
This is a function that generates a footer to put after all other options in help output.
Definition CLI11.hpp:4682

◆ footer() [2/2]

App * CLI::App::footer ( std::string footer_string)
inline

Definition at line 6030 of file CLI11.hpp.

6030 {
6031 footer_ = std::move(footer_string);
6032 return this;
6033 }

◆ formatter()

App * CLI::App::formatter ( std::shared_ptr< FormatterBase > fmt)
inline

Definition at line 5058 of file CLI11.hpp.

5058 {
5059 formatter_ = fmt;
5060 return this;
5061 }

◆ formatter_fn()

App * CLI::App::formatter_fn ( std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
inline

Definition at line 5064 of file CLI11.hpp.

5064 {
5065 formatter_ = std::make_shared<FormatterLambda>(fmt);
5066 return this;
5067 }

◆ get_aliases()

const std::vector< std::string > & CLI::App::get_aliases ( ) const
inline

Definition at line 6267 of file CLI11.hpp.

6267{ return aliases_; }

◆ get_allow_config_extras()

config_extras_mode CLI::App::get_allow_config_extras ( ) const
inline

Definition at line 6240 of file CLI11.hpp.

6240{ return allow_config_extras_; }
Here is the caller graph for this function:

◆ get_allow_extras()

bool CLI::App::get_allow_extras ( ) const
inline

Definition at line 6220 of file CLI11.hpp.

6220{ return allow_extras_; }

◆ get_allow_windows_style_options()

bool CLI::App::get_allow_windows_style_options ( ) const
inline

Definition at line 6190 of file CLI11.hpp.

◆ get_config_formatter()

std::shared_ptr< Config > CLI::App::get_config_formatter ( ) const
inline

Definition at line 6069 of file CLI11.hpp.

6069{ return config_formatter_; }

◆ get_config_formatter_base()

std::shared_ptr< ConfigBase > CLI::App::get_config_formatter_base ( ) const
inline

Definition at line 6072 of file CLI11.hpp.

6072 {
6073 return std::dynamic_pointer_cast<ConfigBase>(config_formatter_);
6074 }

◆ get_config_ptr() [1/2]

Option * CLI::App::get_config_ptr ( )
inline

Definition at line 6252 of file CLI11.hpp.

6252{ return config_ptr_; }

◆ get_config_ptr() [2/2]

const Option * CLI::App::get_config_ptr ( ) const
inline

Definition at line 6255 of file CLI11.hpp.

6255{ return config_ptr_; }

◆ get_configurable()

bool CLI::App::get_configurable ( ) const
inline

Definition at line 6196 of file CLI11.hpp.

6196{ return configurable_; }

◆ get_description()

std::string CLI::App::get_description ( ) const
inline

Definition at line 6077 of file CLI11.hpp.

6077{ return description_; }

◆ get_disabled()

bool CLI::App::get_disabled ( ) const
inline

Definition at line 6226 of file CLI11.hpp.

6226{ return disabled_; }

◆ get_disabled_by_default()

bool CLI::App::get_disabled_by_default ( ) const
inline

Definition at line 6232 of file CLI11.hpp.

◆ get_display_name()

std::string CLI::App::get_display_name ( ) const
inline

Definition at line 6276 of file CLI11.hpp.

6276{ return (!name_.empty()) ? name_ : "[Option Group: " + get_group() + "]"; }
const std::string & get_group() const
Get the group of this subcommand.
Definition CLI11.hpp:6199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_enabled_by_default()

bool CLI::App::get_enabled_by_default ( ) const
inline

Definition at line 6235 of file CLI11.hpp.

◆ get_fallthrough()

bool CLI::App::get_fallthrough ( ) const
inline

Definition at line 6187 of file CLI11.hpp.

6187{ return fallthrough_; }

◆ get_footer()

std::string CLI::App::get_footer ( ) const
inline

Definition at line 6202 of file CLI11.hpp.

6202{ return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_; }

◆ get_formatter()

std::shared_ptr< FormatterBase > CLI::App::get_formatter ( ) const
inline

Definition at line 6066 of file CLI11.hpp.

6066{ return formatter_; }

◆ get_group()

const std::string & CLI::App::get_group ( ) const
inline

Definition at line 6199 of file CLI11.hpp.

6199{ return group_; }
Here is the caller graph for this function:

◆ get_groups()

std::vector< std::string > CLI::App::get_groups ( ) const
inline

Definition at line 6308 of file CLI11.hpp.

6308 {
6309 std::vector<std::string> groups;
6310
6311 for(const Option_p &opt : options_) {
6312 // Add group if it is not already in there
6313 if(std::find(groups.begin(), groups.end(), opt->get_group()) == groups.end()) {
6314 groups.push_back(opt->get_group());
6315 }
6316 }
6317
6318 return groups;
6319 }
Here is the call graph for this function:

◆ get_help_all_ptr()

const Option * CLI::App::get_help_all_ptr ( ) const
inline

Definition at line 6249 of file CLI11.hpp.

6249{ return help_all_ptr_; }
Here is the caller graph for this function:

◆ get_help_ptr() [1/2]

Option * CLI::App::get_help_ptr ( )
inline

Definition at line 6243 of file CLI11.hpp.

6243{ return help_ptr_; }
Here is the caller graph for this function:

◆ get_help_ptr() [2/2]

const Option * CLI::App::get_help_ptr ( ) const
inline

Definition at line 6246 of file CLI11.hpp.

6246{ return help_ptr_; }

◆ get_ignore_case()

bool CLI::App::get_ignore_case ( ) const
inline

Definition at line 6181 of file CLI11.hpp.

6181{ return ignore_case_; }

◆ get_ignore_underscore()

bool CLI::App::get_ignore_underscore ( ) const
inline

Definition at line 6184 of file CLI11.hpp.

6184{ return ignore_underscore_; }

◆ get_immediate_callback()

bool CLI::App::get_immediate_callback ( ) const
inline

Definition at line 6229 of file CLI11.hpp.

6229{ return immediate_callback_; }

◆ get_name()

const std::string & CLI::App::get_name ( ) const
inline

Definition at line 6264 of file CLI11.hpp.

6264{ return name_; }
Here is the caller graph for this function:

◆ get_option() [1/2]

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

Definition at line 6166 of file CLI11.hpp.

6166 {
6167 auto opt = get_option_no_throw(option_name);
6168 if(opt == nullptr) {
6169 throw OptionNotFound(option_name);
6170 }
6171 return opt;
6172 }
Here is the call graph for this function:

◆ get_option() [2/2]

const Option * CLI::App::get_option ( std::string option_name) const
inline

Definition at line 6157 of file CLI11.hpp.

6157 {
6158 auto opt = get_option_no_throw(option_name);
6159 if(opt == nullptr) {
6160 throw OptionNotFound(option_name);
6161 }
6162 return opt;
6163 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_option_group()

App * CLI::App::get_option_group ( std::string group_name) const
inline

Definition at line 5633 of file CLI11.hpp.

5633 {
5634 for(const App_p &app : subcommands_) {
5635 if(app->name_.empty() && app->group_ == group_name) {
5636 return app.get();
5637 }
5638 }
5639 throw OptionNotFound(group_name);
5640 }

◆ get_option_no_throw() [1/2]

const Option * CLI::App::get_option_no_throw ( std::string option_name) const
inlinenoexcept

Definition at line 6138 of file CLI11.hpp.

6138 {
6139 for(const Option_p &opt : options_) {
6140 if(opt->check_name(option_name)) {
6141 return opt.get();
6142 }
6143 }
6144 for(const auto &subc : subcommands_) {
6145 // also check down into nameless subcommands
6146 if(subc->get_name().empty()) {
6147 auto opt = subc->get_option_no_throw(option_name);
6148 if(opt != nullptr) {
6149 return opt;
6150 }
6151 }
6152 }
6153 return nullptr;
6154 }
Here is the call graph for this function:

◆ get_option_no_throw() [2/2]

Option * CLI::App::get_option_no_throw ( std::string option_name)
inlinenoexcept

Definition at line 6119 of file CLI11.hpp.

6119 {
6120 for(Option_p &opt : options_) {
6121 if(opt->check_name(option_name)) {
6122 return opt.get();
6123 }
6124 }
6125 for(auto &subc : subcommands_) {
6126 // also check down into nameless subcommands
6127 if(subc->get_name().empty()) {
6128 auto opt = subc->get_option_no_throw(option_name);
6129 if(opt != nullptr) {
6130 return opt;
6131 }
6132 }
6133 }
6134 return nullptr;
6135 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_options() [1/2]

std::vector< const Option * > CLI::App::get_options ( const std::function< bool(const Option *)> filter = {}) const
inline

Definition at line 6086 of file CLI11.hpp.

6086 {}) const {
6087 std::vector<const Option *> options(options_.size());
6088 std::transform(std::begin(options_), std::end(options_), std::begin(options), [](const Option_p &val) {
6089 return val.get();
6090 });
6091
6092 if(filter) {
6093 options.erase(std::remove_if(std::begin(options),
6094 std::end(options),
6095 [&filter](const Option *opt) { return !filter(opt); }),
6096 std::end(options));
6097 }
6098
6099 return options;
6100 }

◆ get_options() [2/2]

std::vector< Option * > CLI::App::get_options ( const std::function< bool(Option *)> filter = {})
inline

Definition at line 6103 of file CLI11.hpp.

6103 {}) {
6104 std::vector<Option *> options(options_.size());
6105 std::transform(std::begin(options_), std::end(options_), std::begin(options), [](const Option_p &val) {
6106 return val.get();
6107 });
6108
6109 if(filter) {
6110 options.erase(
6111 std::remove_if(std::begin(options), std::end(options), [&filter](Option *opt) { return !filter(opt); }),
6112 std::end(options));
6113 }
6114
6115 return options;
6116 }

◆ get_parent() [1/2]

App * CLI::App::get_parent ( )
inline

Definition at line 6258 of file CLI11.hpp.

6258{ return parent_; }
Here is the caller graph for this function:

◆ get_parent() [2/2]

const App * CLI::App::get_parent ( ) const
inline

Definition at line 6261 of file CLI11.hpp.

6261{ return parent_; }

◆ get_positionals_at_end()

bool CLI::App::get_positionals_at_end ( ) const
inline

Definition at line 6193 of file CLI11.hpp.

6193{ return positionals_at_end_; }

◆ get_prefix_command()

bool CLI::App::get_prefix_command ( ) const
inline

Definition at line 6217 of file CLI11.hpp.

6217{ return prefix_command_; }

◆ get_require_option_max()

std::size_t CLI::App::get_require_option_max ( ) const
inline

Definition at line 6214 of file CLI11.hpp.

6214{ return require_option_max_; }

◆ get_require_option_min()

std::size_t CLI::App::get_require_option_min ( ) const
inline

Definition at line 6211 of file CLI11.hpp.

6211{ return require_option_min_; }

◆ get_require_subcommand_max()

std::size_t CLI::App::get_require_subcommand_max ( ) const
inline

Definition at line 6208 of file CLI11.hpp.

6208{ return require_subcommand_max_; }

◆ get_require_subcommand_min()

std::size_t CLI::App::get_require_subcommand_min ( ) const
inline

Definition at line 6205 of file CLI11.hpp.

6205{ return require_subcommand_min_; }

◆ get_required()

bool CLI::App::get_required ( ) const
inline

Definition at line 6223 of file CLI11.hpp.

6223{ return required_; }
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app.
Definition CLI11.hpp:4644

◆ get_subcommand() [1/3]

App * CLI::App::get_subcommand ( const App * subcom) const
inline

Check to see if a subcommand is part of this command (doesn't have to be in command line) returns the first subcommand if passed a nullptr

Definition at line 5578 of file CLI11.hpp.

5578 {
5579 if(subcom == nullptr)
5580 throw OptionNotFound("nullptr passed");
5581 for(const App_p &subcomptr : subcommands_)
5582 if(subcomptr.get() == subcom)
5583 return subcomptr.get();
5584 throw OptionNotFound(subcom->get_name());
5585 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subcommand() [2/3]

App * CLI::App::get_subcommand ( int index = 0) const
inline

Definition at line 5595 of file CLI11.hpp.

5595 {
5596 if(index >= 0) {
5597 auto uindex = static_cast<unsigned>(index);
5598 if(uindex < subcommands_.size())
5599 return subcommands_[uindex].get();
5600 }
5601 throw OptionNotFound(std::to_string(index));
5602 }

◆ get_subcommand() [3/3]

App * CLI::App::get_subcommand ( std::string subcom) const
inline

Definition at line 5588 of file CLI11.hpp.

5588 {
5589 auto subc = _find_subcommand(subcom, false, false);
5590 if(subc == nullptr)
5591 throw OptionNotFound(subcom);
5592 return subc;
5593 }
Here is the call graph for this function:

◆ get_subcommand_ptr() [1/3]

CLI::App_p CLI::App::get_subcommand_ptr ( App * subcom) const
inline

Definition at line 5605 of file CLI11.hpp.

5605 {
5606 if(subcom == nullptr)
5607 throw OptionNotFound("nullptr passed");
5608 for(const App_p &subcomptr : subcommands_)
5609 if(subcomptr.get() == subcom)
5610 return subcomptr;
5611 throw OptionNotFound(subcom->get_name());
5612 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subcommand_ptr() [2/3]

CLI::App_p CLI::App::get_subcommand_ptr ( int index = 0) const
inline

Definition at line 5623 of file CLI11.hpp.

5623 {
5624 if(index >= 0) {
5625 auto uindex = static_cast<unsigned>(index);
5626 if(uindex < subcommands_.size())
5627 return subcommands_[uindex];
5628 }
5629 throw OptionNotFound(std::to_string(index));
5630 }

◆ get_subcommand_ptr() [3/3]

CLI::App_p CLI::App::get_subcommand_ptr ( std::string subcom) const
inline

Definition at line 5615 of file CLI11.hpp.

5615 {
5616 for(const App_p &subcomptr : subcommands_)
5617 if(subcomptr->check_name(subcom))
5618 return subcomptr;
5619 throw OptionNotFound(subcom);
5620 }

◆ get_subcommands() [1/3]

std::vector< App * > CLI::App::get_subcommands ( ) const
inline

Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command line order; use parsed = false to get the original definition list.)

Definition at line 5893 of file CLI11.hpp.

5893{ return parsed_subcommands_; }
Here is the caller graph for this function:

◆ get_subcommands() [2/3]

std::vector< App * > CLI::App::get_subcommands ( const std::function< bool(App *)> & filter)
inline

Get a filtered subcommand pointer list from the original definition list. An empty function will provide all subcommands

Definition at line 5915 of file CLI11.hpp.

5915 {
5916 std::vector<App *> subcomms(subcommands_.size());
5917 std::transform(std::begin(subcommands_), std::end(subcommands_), std::begin(subcomms), [](const App_p &v) {
5918 return v.get();
5919 });
5920
5921 if(filter) {
5922 subcomms.erase(
5923 std::remove_if(std::begin(subcomms), std::end(subcomms), [&filter](App *app) { return !filter(app); }),
5924 std::end(subcomms));
5925 }
5926
5927 return subcomms;
5928 }

◆ get_subcommands() [3/3]

std::vector< const App * > CLI::App::get_subcommands ( const std::function< bool(const App *)> & filter) const
inline

Get a filtered subcommand pointer list from the original definition list. An empty function will provide all subcommands (const)

Definition at line 5897 of file CLI11.hpp.

5897 {
5898 std::vector<const App *> subcomms(subcommands_.size());
5899 std::transform(std::begin(subcommands_), std::end(subcommands_), std::begin(subcomms), [](const App_p &v) {
5900 return v.get();
5901 });
5902
5903 if(filter) {
5904 subcomms.erase(std::remove_if(std::begin(subcomms),
5905 std::end(subcomms),
5906 [&filter](const App *app) { return !filter(app); }),
5907 std::end(subcomms));
5908 }
5909
5910 return subcomms;
5911 }

◆ get_validate_positionals()

bool CLI::App::get_validate_positionals ( ) const
inline

Definition at line 6237 of file CLI11.hpp.

6237{ return validate_positionals_; }

◆ got_subcommand() [1/2]

bool CLI::App::got_subcommand ( const App * subcom) const
inline

Definition at line 5931 of file CLI11.hpp.

5931 {
5932 // get subcom needed to verify that this was a real subcommand
5933 return get_subcommand(subcom)->parsed_ > 0;
5934 }
Here is the call graph for this function:

◆ got_subcommand() [2/2]

bool CLI::App::got_subcommand ( std::string subcommand_name) const
inline

Definition at line 5937 of file CLI11.hpp.

5937{ return get_subcommand(subcommand_name)->parsed_ > 0; }
Here is the call graph for this function:

◆ group()

App * CLI::App::group ( std::string group_name)
inline

Definition at line 5664 of file CLI11.hpp.

5664 {
5665 group_ = group_name;
5666 return this;
5667 }
Here is the caller graph for this function:

◆ help()

std::string CLI::App::help ( std::string prev = "",
AppFormatMode mode = AppFormatMode::Normal ) const
inline

Makes a help message, using the currently configured formatter Will only do one subcommand at a time

Definition at line 6047 of file CLI11.hpp.

6047 {
6048 if(prev.empty())
6049 prev = get_name();
6050 else
6051 prev += " " + get_name();
6052
6053 // Delegate to subcommand if needed
6054 auto selected_subcommands = get_subcommands();
6055 if(!selected_subcommands.empty()) {
6056 return selected_subcommands.at(0)->help(prev, mode);
6057 }
6058 return formatter_->make_help(this, prev, mode);
6059 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ignore_case()

App * CLI::App::ignore_case ( bool value = true)
inline

Definition at line 5009 of file CLI11.hpp.

5009 {
5010 if(value && !ignore_case_) {
5011 ignore_case_ = true;
5012 auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this;
5013 auto &match = _compare_subcommand_names(*this, *p);
5014 if(!match.empty()) {
5015 ignore_case_ = false; // we are throwing so need to be exception invariant
5016 throw OptionAlreadyAdded("ignore case would cause subcommand name conflicts: " + match);
5017 }
5018 }
5020 return this;
5021 }
const mie::Vuint & p
Definition bn.cpp:27
Here is the call graph for this function:

◆ ignore_underscore()

App * CLI::App::ignore_underscore ( bool value = true)
inline

Definition at line 5043 of file CLI11.hpp.

5043 {
5044 if(value && !ignore_underscore_) {
5045 ignore_underscore_ = true;
5046 auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this;
5047 auto &match = _compare_subcommand_names(*this, *p);
5048 if(!match.empty()) {
5049 ignore_underscore_ = false;
5050 throw OptionAlreadyAdded("ignore underscore would cause subcommand name conflicts: " + match);
5051 }
5052 }
5054 return this;
5055 }
Here is the call graph for this function:

◆ immediate_callback()

App * CLI::App::immediate_callback ( bool immediate = true)
inline

Definition at line 4967 of file CLI11.hpp.

4967 {
4968 immediate_callback_ = immediate;
4972 }
4973 } else if(!(final_callback_) && parse_complete_callback_) {
4975 }
4976 return this;
4977 }
void swap(picojson::value &x, picojson::value &y)
Here is the call graph for this function:

◆ increment_parsed()

void CLI::App::increment_parsed ( )
inlineprotected

Definition at line 6787 of file CLI11.hpp.

6787 {
6788 ++parsed_;
6789 for(App_p &sub : subcommands_) {
6790 if(sub->get_name().empty())
6791 sub->increment_parsed();
6792 }
6793 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

App * CLI::App::name ( std::string app_name = "")
inline

Definition at line 4889 of file CLI11.hpp.

4889 {
4890
4891 if(parent_ != nullptr) {
4892 auto oname = name_;
4893 name_ = app_name;
4895 if(!res.empty()) {
4896 name_ = oname;
4897 throw(OptionAlreadyAdded(app_name + " conflicts with existing subcommand names"));
4898 }
4899 } else {
4900 name_ = app_name;
4901 }
4902 has_automatic_name_ = false;
4903 return this;
4904 }
bool has_automatic_name_
If set to true the name was automatically generated from the command line vs a user set name.
Definition CLI11.hpp:4641
Here is the call graph for this function:

◆ needs() [1/2]

App * CLI::App::needs ( App * app)
inline

Definition at line 5972 of file CLI11.hpp.

5972 {
5973 if(app == nullptr) {
5974 throw OptionNotFound("nullptr passed");
5975 }
5976 if(app == this) {
5977 throw OptionNotFound("cannot self reference in needs");
5978 }
5979 need_subcommands_.insert(app);
5980 return this;
5981 }

◆ needs() [2/2]

App * CLI::App::needs ( Option * opt)
inline

Definition at line 5964 of file CLI11.hpp.

5964 {
5965 if(opt == nullptr) {
5966 throw OptionNotFound("nullptr passed");
5967 }
5968 need_options_.insert(opt);
5969 return this;
5970 }

◆ operator bool()

CLI::App::operator bool ( ) const
inlineexplicit

Check to see if this subcommand was parsed, true only if received on command line. This allows the subcommand to be directly checked.

Definition at line 5736 of file CLI11.hpp.

5736{ return parsed_ > 0; }

◆ operator=()

App & CLI::App::operator= ( const App & )
delete

◆ operator[]() [1/2]

const Option * CLI::App::operator[] ( const char * option_name) const
inline

Definition at line 6178 of file CLI11.hpp.

6178{ return get_option(option_name); }
Here is the call graph for this function:

◆ operator[]() [2/2]

const Option * CLI::App::operator[] ( const std::string & option_name) const
inline

Definition at line 6175 of file CLI11.hpp.

6175{ return get_option(option_name); }
Here is the call graph for this function:

◆ option_defaults()

OptionDefaults * CLI::App::option_defaults ( )
inline

Definition at line 5079 of file CLI11.hpp.

5079{ return &option_defaults_; }

◆ parse() [1/4]

void CLI::App::parse ( int argc,
const char *const * argv )
inline

Parses the command line - throws errors. This must be called after the options are in but before the rest of the program.

Definition at line 5769 of file CLI11.hpp.

5769 {
5770 // If the name is not set, read from command line
5771 if(name_.empty() || has_automatic_name_) {
5772 has_automatic_name_ = true;
5773 name_ = argv[0];
5774 }
5775
5776 std::vector<std::string> args;
5777 args.reserve(static_cast<std::size_t>(argc) - 1);
5778 for(int i = argc - 1; i > 0; i--)
5779 args.emplace_back(argv[i]);
5780 parse(std::move(args));
5781 }
void parse(int argc, const char *const *argv)
Definition CLI11.hpp:5769
char ** argv
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse() [2/4]

void CLI::App::parse ( std::string commandline,
bool program_name_included = false )
inline

Parse a single string as if it contained command line arguments. This function splits the string into arguments then calls parse(std::vector<std::string> &) the function takes an optional boolean argument specifying if the programName is included in the string to process

Definition at line 5787 of file CLI11.hpp.

5787 {
5788
5789 if(program_name_included) {
5790 auto nstr = detail::split_program_name(commandline);
5791 if((name_.empty()) || (has_automatic_name_)) {
5792 has_automatic_name_ = true;
5793 name_ = nstr.first;
5794 }
5795 commandline = std::move(nstr.second);
5796 } else
5797 detail::trim(commandline);
5798 // the next section of code is to deal with quoted arguments after an '=' or ':' for windows like operations
5799 if(!commandline.empty()) {
5800 commandline = detail::find_and_modify(commandline, "=", detail::escape_detect);
5802 commandline = detail::find_and_modify(commandline, ":", detail::escape_detect);
5803 }
5804
5805 auto args = detail::split_up(std::move(commandline));
5806 // remove all empty strings
5807 args.erase(std::remove(args.begin(), args.end(), std::string{}), args.end());
5808 std::reverse(args.begin(), args.end());
5809
5810 parse(std::move(args));
5811 }
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition CLI11.hpp:412
std::string & trim(std::string &str)
Trim whitespace from string.
Definition CLI11.hpp:267
std::pair< std::string, std::string > split_program_name(std::string commandline)
Definition CLI11.hpp:3128
Here is the call graph for this function:

◆ parse() [3/4]

void CLI::App::parse ( std::vector< std::string > && args)
inline

Definition at line 5835 of file CLI11.hpp.

5835 {
5836 // Clear if parsed
5837 if(parsed_ > 0)
5838 clear();
5839
5840 // parsed_ is incremented in commands/subcommands,
5841 // but placed here to make sure this is cleared when
5842 // running parse after an error is thrown, even by _validate or _configure.
5843 parsed_ = 1;
5844 _validate();
5845 _configure();
5846 // set the parent as nullptr as this object should be the top now
5847 parent_ = nullptr;
5848 parsed_ = 0;
5849
5850 _parse(std::move(args));
5851 run_callback();
5852 }
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition CLI11.hpp:6795
void _configure()
Definition CLI11.hpp:6419
void _validate() const
Definition CLI11.hpp:6380
Here is the call graph for this function:

◆ parse() [4/4]

void CLI::App::parse ( std::vector< std::string > & args)
inline

The real work is done here. Expects a reversed vector. Changes the vector to the remaining options.

Definition at line 5815 of file CLI11.hpp.

5815 {
5816 // Clear if parsed
5817 if(parsed_ > 0)
5818 clear();
5819
5820 // parsed_ is incremented in commands/subcommands,
5821 // but placed here to make sure this is cleared when
5822 // running parse after an error is thrown, even by _validate or _configure.
5823 parsed_ = 1;
5824 _validate();
5825 _configure();
5826 // set the parent as nullptr as this object should be the top now
5827 parent_ = nullptr;
5828 parsed_ = 0;
5829
5830 _parse(args);
5831 run_callback();
5832 }
Here is the call graph for this function:

◆ parse_complete_callback()

App * CLI::App::parse_complete_callback ( std::function< void()> pc_callback)
inline

Set a callback to execute when parsing has completed for the app

Definition at line 4876 of file CLI11.hpp.

4876 {
4877 parse_complete_callback_ = std::move(pc_callback);
4878 return this;
4879 }

◆ parse_order()

const std::vector< Option * > & CLI::App::parse_order ( ) const
inline

Definition at line 6322 of file CLI11.hpp.

6322{ return parse_order_; }

◆ parsed()

bool CLI::App::parsed ( ) const
inline

Definition at line 5076 of file CLI11.hpp.

5076{ return parsed_ > 0; }

◆ positionals_at_end()

App * CLI::App::positionals_at_end ( bool value = true)
inline

Definition at line 5031 of file CLI11.hpp.

5031 {
5033 return this;
5034 }

◆ pre_callback()

virtual void CLI::App::pre_callback ( )
inlinevirtual

This allows subclasses to inject code before callbacks but after parse.

This does not run if any errors or help is thrown.

Definition at line 5745 of file CLI11.hpp.

5745{}
Here is the caller graph for this function:

◆ prefix_command()

App * CLI::App::prefix_command ( bool allow = true)
inline

Definition at line 5003 of file CLI11.hpp.

5003 {
5004 prefix_command_ = allow;
5005 return this;
5006 }

◆ preparse_callback()

App * CLI::App::preparse_callback ( std::function< void(std::size_t)> pp_callback)
inline

Set a callback to execute prior to parsing.

Definition at line 4883 of file CLI11.hpp.

4883 {
4884 pre_parse_callback_ = std::move(pp_callback);
4885 return this;
4886 }
Here is the caller graph for this function:

◆ remaining()

std::vector< std::string > CLI::App::remaining ( bool recurse = false) const
inline

Definition at line 6325 of file CLI11.hpp.

6325 {
6326 std::vector<std::string> miss_list;
6327 for(const std::pair<detail::Classifier, std::string> &miss : missing_) {
6328 miss_list.push_back(std::get<1>(miss));
6329 }
6330 // Get from a subcommand that may allow extras
6331 if(recurse) {
6332 if(!allow_extras_) {
6333 for(const auto &sub : subcommands_) {
6334 if(sub->name_.empty() && !sub->missing_.empty()) {
6335 for(const std::pair<detail::Classifier, std::string> &miss : sub->missing_) {
6336 miss_list.push_back(std::get<1>(miss));
6337 }
6338 }
6339 }
6340 }
6341 // Recurse into subcommands
6342
6343 for(const App *sub : parsed_subcommands_) {
6344 std::vector<std::string> output = sub->remaining(recurse);
6345 std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list));
6346 }
6347 }
6348 return miss_list;
6349 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remaining_for_passthrough()

std::vector< std::string > CLI::App::remaining_for_passthrough ( bool recurse = false) const
inline

Definition at line 6352 of file CLI11.hpp.

6352 {
6353 std::vector<std::string> miss_list = remaining(recurse);
6354 std::reverse(std::begin(miss_list), std::end(miss_list));
6355 return miss_list;
6356 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remaining_size()

std::size_t CLI::App::remaining_size ( bool recurse = false) const
inline

Definition at line 6359 of file CLI11.hpp.

6359 {
6360 auto remaining_options = static_cast<std::size_t>(std::count_if(
6361 std::begin(missing_), std::end(missing_), [](const std::pair<detail::Classifier, std::string> &val) {
6362 return val.first != detail::Classifier::POSITIONAL_MARK;
6363 }));
6364
6365 if(recurse) {
6366 for(const App_p &sub : subcommands_) {
6367 remaining_options += sub->remaining_size(recurse);
6368 }
6369 }
6370 return remaining_options;
6371 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_excludes() [1/2]

bool CLI::App::remove_excludes ( App * app)
inline

Definition at line 5994 of file CLI11.hpp.

5994 {
5995 auto iterator = std::find(std::begin(exclude_subcommands_), std::end(exclude_subcommands_), app);
5996 if(iterator == std::end(exclude_subcommands_)) {
5997 return false;
5998 }
5999 auto other_app = *iterator;
6000 exclude_subcommands_.erase(iterator);
6001 other_app->remove_excludes(this);
6002 return true;
6003 }

◆ remove_excludes() [2/2]

bool CLI::App::remove_excludes ( Option * opt)
inline

Definition at line 5984 of file CLI11.hpp.

5984 {
5985 auto iterator = std::find(std::begin(exclude_options_), std::end(exclude_options_), opt);
5986 if(iterator == std::end(exclude_options_)) {
5987 return false;
5988 }
5989 exclude_options_.erase(iterator);
5990 return true;
5991 }

◆ remove_needs() [1/2]

bool CLI::App::remove_needs ( App * app)
inline

Definition at line 6016 of file CLI11.hpp.

6016 {
6017 auto iterator = std::find(std::begin(need_subcommands_), std::end(need_subcommands_), app);
6018 if(iterator == std::end(need_subcommands_)) {
6019 return false;
6020 }
6021 need_subcommands_.erase(iterator);
6022 return true;
6023 }

◆ remove_needs() [2/2]

bool CLI::App::remove_needs ( Option * opt)
inline

Definition at line 6006 of file CLI11.hpp.

6006 {
6007 auto iterator = std::find(std::begin(need_options_), std::end(need_options_), opt);
6008 if(iterator == std::end(need_options_)) {
6009 return false;
6010 }
6011 need_options_.erase(iterator);
6012 return true;
6013 }

◆ remove_option()

bool CLI::App::remove_option ( Option * opt)
inline

Definition at line 5501 of file CLI11.hpp.

5501 {
5502 // Make sure no links exist
5503 for(Option_p &op : options_) {
5504 op->remove_needs(opt);
5505 op->remove_excludes(opt);
5506 }
5507
5508 if(help_ptr_ == opt)
5509 help_ptr_ = nullptr;
5510 if(help_all_ptr_ == opt)
5511 help_all_ptr_ = nullptr;
5512
5513 auto iterator =
5514 std::find_if(std::begin(options_), std::end(options_), [opt](const Option_p &v) { return v.get() == opt; });
5515 if(iterator != std::end(options_)) {
5516 options_.erase(iterator);
5517 return true;
5518 }
5519 return false;
5520 }
Here is the caller graph for this function:

◆ remove_subcommand()

bool CLI::App::remove_subcommand ( App * subcom)
inline

Definition at line 5561 of file CLI11.hpp.

5561 {
5562 // Make sure no links exist
5563 for(App_p &sub : subcommands_) {
5564 sub->remove_excludes(subcom);
5565 sub->remove_needs(subcom);
5566 }
5567
5568 auto iterator = std::find_if(
5569 std::begin(subcommands_), std::end(subcommands_), [subcom](const App_p &v) { return v.get() == subcom; });
5570 if(iterator != std::end(subcommands_)) {
5571 subcommands_.erase(iterator);
5572 return true;
5573 }
5574 return false;
5575 }
Here is the call graph for this function:

◆ require_option() [1/3]

App * CLI::App::require_option ( )
inline

Definition at line 5699 of file CLI11.hpp.

5699 {
5702 return this;
5703 }

◆ require_option() [2/3]

App * CLI::App::require_option ( int value)
inline

Require an option to be given (does not affect help call) The number required can be given. Negative values indicate maximum number allowed (0 for any number).

Definition at line 5708 of file CLI11.hpp.

5708 {
5709 if(value < 0) {
5711 require_option_max_ = static_cast<std::size_t>(-value);
5712 } else {
5713 require_option_min_ = static_cast<std::size_t>(value);
5714 require_option_max_ = static_cast<std::size_t>(value);
5715 }
5716 return this;
5717 }

◆ require_option() [3/3]

App * CLI::App::require_option ( std::size_t min,
std::size_t max )
inline

Explicitly control the number of options required. Setting 0 for the max means unlimited number allowed. Max number inheritable.

Definition at line 5721 of file CLI11.hpp.

5721 {
5723 require_option_max_ = max;
5724 return this;
5725 }
const T & min(const T &a, const T &b)
Definition utility.hpp:140

◆ require_subcommand() [1/3]

App * CLI::App::require_subcommand ( )
inline

Definition at line 5670 of file CLI11.hpp.

5670 {
5673 return this;
5674 }

◆ require_subcommand() [2/3]

App * CLI::App::require_subcommand ( int value)
inline

Require a subcommand to be given (does not affect help call) The number required can be given. Negative values indicate maximum number allowed (0 for any number). Max number inheritable.

Definition at line 5679 of file CLI11.hpp.

5679 {
5680 if(value < 0) {
5682 require_subcommand_max_ = static_cast<std::size_t>(-value);
5683 } else {
5684 require_subcommand_min_ = static_cast<std::size_t>(value);
5685 require_subcommand_max_ = static_cast<std::size_t>(value);
5686 }
5687 return this;
5688 }

◆ require_subcommand() [3/3]

App * CLI::App::require_subcommand ( std::size_t min,
std::size_t max )
inline

Explicitly control the number of subcommands required. Setting 0 for the max means unlimited number allowed. Max number inheritable.

Definition at line 5692 of file CLI11.hpp.

5692 {
5695 return this;
5696 }

◆ required()

App * CLI::App::required ( bool require = true)
inline

Definition at line 4933 of file CLI11.hpp.

4933 {
4935 return this;
4936 }
void require(ParseState &state, TokenType type)
Definition Parse.cpp:78

◆ run_callback()

void CLI::App::run_callback ( bool final_mode = false)
inlineprotected

Definition at line 6439 of file CLI11.hpp.

6439 {
6440 pre_callback();
6441 // in the main app if immediate_callback_ is set it runs the main callback before the used subcommands
6442 if(!final_mode && parse_complete_callback_) {
6444 }
6445 // run the callbacks for the received subcommands
6446 for(App *subc : get_subcommands()) {
6447 subc->run_callback(true);
6448 }
6449 // now run callbacks for option_groups
6450 for(auto &subc : subcommands_) {
6451 if(subc->name_.empty() && subc->count_all() > 0) {
6452 subc->run_callback(true);
6453 }
6454 }
6455
6456 // finally run the main callback
6457 if(final_callback_ && (parsed_ > 0)) {
6458 if(!name_.empty() || count_all() > 0) {
6460 }
6461 }
6462 }
virtual void pre_callback()
Definition CLI11.hpp:5745
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_config()

Option * CLI::App::set_config ( std::string option_name = "",
std::string default_filename = "",
const std::string & help_message = "Read an ini file",
bool config_required = false )
inline

Definition at line 5474 of file CLI11.hpp.

5477 {
5478
5479 // Remove existing config if present
5480 if(config_ptr_ != nullptr) {
5482 config_ptr_ = nullptr; // need to remove the config_ptr completely
5483 }
5484
5485 // Only add config if option passed
5486 if(!option_name.empty()) {
5487 config_ptr_ = add_option(option_name, help_message);
5488 if(config_required) {
5490 }
5491 if(!default_filename.empty()) {
5492 config_ptr_->default_str(std::move(default_filename));
5493 }
5494 config_ptr_->configurable(false);
5495 }
5496
5497 return config_ptr_;
5498 }
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
Definition CLI11.hpp:5501
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition CLI11.hpp:3481
CRTP * required(bool value=true)
Set the option as required.
Definition CLI11.hpp:3400
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition CLI11.hpp:4379
Here is the call graph for this function:

◆ set_help_all_flag()

Option * CLI::App::set_help_all_flag ( std::string help_name = "",
const std::string & help_description = "" )
inline

Definition at line 5220 of file CLI11.hpp.

5220 {
5221 // take flag_description by const reference otherwise add_flag tries to assign to flag_description
5222 if(help_all_ptr_ != nullptr) {
5224 help_all_ptr_ = nullptr;
5225 }
5226
5227 // Empty name will simply remove the help all flag
5228 if(!help_name.empty()) {
5229 help_all_ptr_ = add_flag(help_name, help_description);
5231 }
5232
5233 return help_all_ptr_;
5234 }
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition CLI11.hpp:5265
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_help_flag()

Option * CLI::App::set_help_flag ( std::string flag_name = "",
const std::string & help_description = "" )
inline

Definition at line 5203 of file CLI11.hpp.

5203 {
5204 // take flag_description by const reference otherwise add_flag tries to assign to help_description
5205 if(help_ptr_ != nullptr) {
5207 help_ptr_ = nullptr;
5208 }
5209
5210 // Empty name will simply remove the help flag
5211 if(!flag_name.empty()) {
5212 help_ptr_ = add_flag(flag_name, help_description);
5213 help_ptr_->configurable(false);
5214 }
5215
5216 return help_ptr_;
5217 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_positionals()

App * CLI::App::validate_positionals ( bool validate = true)
inline

Definition at line 4980 of file CLI11.hpp.

4980 {
4982 return this;
4983 }
bool validate(server *, websocketpp::connection_hdl)
Here is the call graph for this function:

Member Data Documentation

◆ aliases_

std::vector<std::string> CLI::App::aliases_ {}
protected

Definition at line 4788 of file CLI11.hpp.

4788{};

◆ allow_config_extras_

config_extras_mode CLI::App::allow_config_extras_ {config_extras_mode::ignore}
protected

If ignore, allow extra arguments in the ini file (ie, don't throw an error). INHERITABLE if error error on an extra argument, and if capture feed it to the app

Definition at line 4635 of file CLI11.hpp.

◆ allow_extras_

bool CLI::App::allow_extras_ {false}
protected

Definition at line 4631 of file CLI11.hpp.

4631{false};

◆ allow_windows_style_options_

bool CLI::App::allow_windows_style_options_
protected
Initial value:
{
false
}

Definition at line 4745 of file CLI11.hpp.

4745 {
4746#ifdef _WIN32
4747 true
4748#else
4749 false
4750#endif
4751 };

◆ config_formatter_

std::shared_ptr<Config> CLI::App::config_formatter_ {new ConfigINI()}
protected

Definition at line 4798 of file CLI11.hpp.

4798{new ConfigINI()};
ConfigBase ConfigINI
the default Config is the INI file format
Definition CLI11.hpp:2057

◆ config_ptr_

Option* CLI::App::config_ptr_ {nullptr}
protected

Definition at line 4795 of file CLI11.hpp.

4795{nullptr};

◆ configurable_

bool CLI::App::configurable_ {false}
protected

Definition at line 4761 of file CLI11.hpp.

4761{false};

◆ default_startup

startup_mode CLI::App::default_startup {startup_mode::stable}
protected

specify the startup mode for the app stable=no change, enabled= startup enabled, disabled=startup disabled

Definition at line 4758 of file CLI11.hpp.

◆ description_

std::string CLI::App::description_ {}
protected

Definition at line 4628 of file CLI11.hpp.

4628{};

◆ disabled_

bool CLI::App::disabled_ {false}
protected

Definition at line 4647 of file CLI11.hpp.

4647{false};

◆ exclude_options_

std::set<Option *> CLI::App::exclude_options_ {}
protected

This is a list of options which are exclusionary to this App, if the options were used this subcommand should not be

Definition at line 4718 of file CLI11.hpp.

4718{};

◆ exclude_subcommands_

std::set<App *> CLI::App::exclude_subcommands_ {}
protected

Definition at line 4714 of file CLI11.hpp.

4714{};

◆ failure_message_

std::function<std::string(const App *, const Error &e)> CLI::App::failure_message_ {FailureMessage::simple}
protected

Definition at line 4694 of file CLI11.hpp.

std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+)
Definition CLI11.hpp:7574

◆ fallthrough_

bool CLI::App::fallthrough_ {false}
protected

Definition at line 4742 of file CLI11.hpp.

4742{false};

◆ final_callback_

std::function<void()> CLI::App::final_callback_ {}
protected

Definition at line 4662 of file CLI11.hpp.

4662{};

◆ footer_

std::string CLI::App::footer_ {}
protected

Definition at line 4679 of file CLI11.hpp.

4679{};

◆ footer_callback_

std::function<std::string()> CLI::App::footer_callback_ {}
protected

Definition at line 4682 of file CLI11.hpp.

4682{};

◆ formatter_

std::shared_ptr<FormatterBase> CLI::App::formatter_ {new Formatter()}
protected

Definition at line 4691 of file CLI11.hpp.

4691{new Formatter()};

◆ group_

std::string CLI::App::group_ {"Subcommands"}
protected

Definition at line 4785 of file CLI11.hpp.

4785{"Subcommands"};

◆ has_automatic_name_

bool CLI::App::has_automatic_name_ {false}
protected

Definition at line 4641 of file CLI11.hpp.

4641{false};

◆ help_all_ptr_

Option* CLI::App::help_all_ptr_ {nullptr}
protected

Definition at line 4688 of file CLI11.hpp.

4688{nullptr};

◆ help_ptr_

Option* CLI::App::help_ptr_ {nullptr}
protected

Definition at line 4685 of file CLI11.hpp.

4685{nullptr};

◆ ignore_case_

bool CLI::App::ignore_case_ {false}
protected

Definition at line 4736 of file CLI11.hpp.

4736{false};

◆ ignore_underscore_

bool CLI::App::ignore_underscore_ {false}
protected

Definition at line 4739 of file CLI11.hpp.

4739{false};

◆ immediate_callback_

bool CLI::App::immediate_callback_ {false}
protected

Flag indicating that the callback for the subcommand should be executed immediately on parse completion which is before help or ini files are processed. INHERITABLE

Definition at line 4654 of file CLI11.hpp.

4654{false};

◆ missing_

missing_t CLI::App::missing_ {}
protected

Pair of classifier, string for missing options. (extra detail is removed on returning from parse)

This is faster and cleaner than storing just a list of strings and reparsing. This may contain the – separator.

Definition at line 4705 of file CLI11.hpp.

4705{};

◆ name_

std::string CLI::App::name_ {}
protected

Definition at line 4625 of file CLI11.hpp.

4625{};

◆ need_options_

std::set<Option *> CLI::App::need_options_ {}
protected

This is a list of options which are required by this app, the list is not mutual, listed options do not need the subcommand not be

Definition at line 4726 of file CLI11.hpp.

4726{};

◆ need_subcommands_

std::set<App *> CLI::App::need_subcommands_ {}
protected

this is a list of subcommands or option groups that are required by this one, the list is not mutual, the listed subcommands do not require this one

Definition at line 4722 of file CLI11.hpp.

4722{};

◆ option_defaults_

OptionDefaults CLI::App::option_defaults_ {}
protected

Definition at line 4669 of file CLI11.hpp.

4669{};

◆ options_

std::vector<Option_p> CLI::App::options_ {}
protected

Definition at line 4672 of file CLI11.hpp.

4672{};

◆ parent_

App* CLI::App::parent_ {nullptr}
protected

Definition at line 4767 of file CLI11.hpp.

4767{nullptr};

◆ parse_complete_callback_

std::function<void()> CLI::App::parse_complete_callback_ {}
protected

Definition at line 4660 of file CLI11.hpp.

4660{};

◆ parse_order_

std::vector<Option *> CLI::App::parse_order_ {}
protected

Definition at line 4708 of file CLI11.hpp.

4708{};

◆ parsed_

std::size_t CLI::App::parsed_ {0}
protected

Definition at line 4770 of file CLI11.hpp.

4770{0};

◆ parsed_subcommands_

std::vector<App *> CLI::App::parsed_subcommands_ {}
protected

Definition at line 4711 of file CLI11.hpp.

4711{};

◆ positionals_at_end_

bool CLI::App::positionals_at_end_ {false}
protected

Definition at line 4753 of file CLI11.hpp.

4753{false};

◆ pre_parse_callback_

std::function<void(std::size_t)> CLI::App::pre_parse_callback_ {}
protected

Definition at line 4657 of file CLI11.hpp.

4657{};

◆ pre_parse_called_

bool CLI::App::pre_parse_called_ {false}
protected

Definition at line 4650 of file CLI11.hpp.

4650{false};

◆ prefix_command_

bool CLI::App::prefix_command_ {false}
protected

Definition at line 4638 of file CLI11.hpp.

4638{false};

◆ require_option_max_

std::size_t CLI::App::require_option_max_ {0}
protected

Definition at line 4782 of file CLI11.hpp.

4782{0};

◆ require_option_min_

std::size_t CLI::App::require_option_min_ {0}
protected

Definition at line 4779 of file CLI11.hpp.

4779{0};

◆ require_subcommand_max_

std::size_t CLI::App::require_subcommand_max_ {0}
protected

Definition at line 4776 of file CLI11.hpp.

4776{0};

◆ require_subcommand_min_

std::size_t CLI::App::require_subcommand_min_ {0}
protected

Definition at line 4773 of file CLI11.hpp.

4773{0};

◆ required_

bool CLI::App::required_ {false}
protected

Definition at line 4644 of file CLI11.hpp.

4644{false};

◆ subcommands_

std::vector<App_p> CLI::App::subcommands_ {}
protected

Definition at line 4733 of file CLI11.hpp.

4733{};

◆ validate_positionals_

bool CLI::App::validate_positionals_ {false}
protected

Definition at line 4764 of file CLI11.hpp.

4764{false};

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