|
cli11
|
A command-line parser, a subcommand, or an option group. More...
Public Member Functions | |
| auto | _move_option (option_t *opt, app_t *app) -> void |
| Moves an option from one application to another. | |
Basic | |
| app_t (std::string app_description="", std::string app_name="") | |
| Constructs a top-level application. | |
| app_t (const app_t &)=delete | |
| auto | operator= (const app_t &) -> app_t &=delete |
| auto | ensure_utf8 (char **argv) -> char ** |
| Converts argv to UTF-8 on Windows; does nothing elsewhere. | |
| auto | callback (std::function< void()> app_callback) -> app_t * |
| Sets the callback run once everything has been parsed and processed. | |
| auto | final_callback (std::function< void()> app_callback) -> app_t * |
| Sets the callback run once everything has been processed. | |
| auto | parse_complete_callback (std::function< void()> pc_callback) -> app_t * |
| Sets the callback run once parsing has finished. | |
| auto | preparse_callback (std::function< void(std::size_t)> pp_callback) -> app_t * |
| Sets the callback run before parsing starts. | |
| auto | name (std::string app_name="") -> app_t * |
| Sets the application or subcommand name. | |
| auto | alias (std::string app_name) -> app_t * |
| Adds an alternative name this subcommand answers to. | |
| auto | allow_extras (bool allow=true) -> app_t * |
| Accepts unmatched arguments instead of reporting them. | |
| auto | allow_extras (extras_mode_t allow) -> app_t * |
| Sets what happens to unmatched arguments. | |
| auto | required (bool require=true) -> app_t * |
| Requires this subcommand to be used. | |
| auto | disabled (bool disable=true) -> app_t * |
| Disables this subcommand or option group. | |
| auto | silent (bool silence=true) -> app_t * |
| Hides this subcommand from the processed subcommand list. | |
| auto | allow_non_standard_option_names (bool allowed=true) -> app_t * |
| Accepts non-standard option names such as -single_dash_flag. | |
| auto | allow_subcommand_prefix_matching (bool allowed=true) -> app_t * |
| Lets a subcommand be matched by a unique prefix of its name. | |
| auto | disabled_by_default (bool disable=true) -> app_t * |
| Makes clear leave this subcommand disabled. | |
| auto | enabled_by_default (bool enable=true) -> app_t * |
| Makes clear leave this subcommand enabled. | |
| auto | immediate_callback (bool immediate=true) -> app_t * |
| Runs this subcommand's callback as soon as it finishes parsing. | |
| auto | validate_positionals (bool validate=true) -> app_t * |
| Validates positionals before assigning them. | |
| auto | validate_optional_arguments (bool validate=true) -> app_t * |
| Validates optional vector arguments before assigning them. | |
| auto | allow_config_extras (bool allow=true) -> app_t * |
| Accepts unmatched configuration entries instead of reporting them. | |
| auto | allow_config_extras (config_extras_mode_t mode) -> app_t * |
| Sets what happens to unmatched configuration entries. | |
| auto | prefix_command (bool is_prefix=true) -> app_t * |
| Stops parsing at the first unrecognised argument. | |
| auto | prefix_command (prefix_command_mode_t mode) -> app_t * |
| Sets when parsing stops early. | |
| auto | ignore_case (bool value=true) -> app_t * |
| Makes name matching case-insensitive. Subcommands inherit this. | |
| auto | allow_windows_style_options (bool value=true) -> app_t * |
| Accepts Windows-style options such as /opt. | |
| auto | positionals_at_end (bool value=true) -> app_t * |
| Requires positionals to appear after every option. | |
| auto | configurable (bool value=true) -> app_t * |
| Lets this subcommand be triggered from a configuration file. | |
| auto | ignore_underscore (bool value=true) -> app_t * |
| Makes name matching ignore underscores. Subcommands inherit this. | |
| auto | formatter (std::shared_ptr< formatter_base_t > fmt) -> app_t * |
| Replaces the help formatter. | |
| auto | formatter_fn (std::function< std::string(const app_t *, std::string, app_format_mode_t)> fmt) -> app_t * |
| Replaces the help formatter with a callable. | |
| auto | config_formatter (std::shared_ptr< config_t > fmt) -> app_t * |
| Replaces the configuration reader and writer. | |
| auto | parsed () const -> bool |
| Reports whether this subcommand appeared on the command line. | |
| auto | option_defaults () -> option_defaults_t * |
| Returns the settings newly added options inherit. | |
Extras for subclassing | |
| virtual auto | pre_callback () -> void |
| Hook run after parsing but before the callbacks. | |
Post parsing | |
| auto | count (std::string option_name) const -> std::size_t |
| Returns how many times an option was used. | |
| auto | get_subcommands () const -> const std::vector< app_t * > & |
| Returns the subcommands that were used, in command-line order. | |
| auto | get_subcommands (const std::function< bool(const app_t *)> &filter) const -> std::vector< const app_t * > |
| Returns the subcommands matching a filter, as defined. | |
| auto | get_subcommands (const std::function< bool(app_t *)> &filter) -> std::vector< app_t * > |
| Returns the subcommands matching a filter, as defined. | |
| auto | got_subcommand (const app_t *subcom) const -> bool |
| Reports whether a subcommand was used. | |
| auto | got_subcommand (std::string subcommand_name) const noexcept -> bool |
| Reports whether a named subcommand was used. | |
| auto | excludes (option_t *opt) -> app_t * |
| Forbids an option from being used alongside this subcommand. | |
| auto | excludes (app_t *app) -> app_t * |
| Forbids a subcommand from being used alongside this one. | |
| auto | needs (option_t *opt) -> app_t * |
| Requires an option to be used alongside this subcommand. | |
| auto | needs (app_t *app) -> app_t * |
| Requires a subcommand to be used alongside this one. | |
| auto | remove_excludes (option_t *opt) -> bool |
| Drops an option exclusion. | |
| auto | remove_excludes (app_t *app) -> bool |
| Drops a subcommand exclusion. | |
| auto | remove_needs (option_t *opt) -> bool |
| Drops an option requirement. | |
| auto | remove_needs (app_t *app) -> bool |
| Drops a subcommand requirement. | |
Protected Member Functions | |
| app_t (std::string app_description, std::string app_name, app_t *parent) | |
| Constructs a subcommand. | |
| auto | _validate () const -> void |
| Checks the option set for conflicts. | |
| auto | _configure () -> void |
| Prepares the subcommand tree for parsing. | |
| auto | run_callback (bool final_mode=false, bool suppress_final_callback=false) -> void |
| Runs this application's callback, and its subcommands', bottom up. | |
| auto | _valid_subcommand (const std::string ¤t, bool ignore_used=true) const -> bool |
| Reports whether a token names a usable subcommand. | |
| auto | _recognize (const std::string ¤t, bool ignore_used_subcommands=true) const -> detail::classifier_t |
| Classifies one command-line argument. | |
| auto | _process_config_file () -> void |
| Reads and applies the configuration file. Main application only. | |
| auto | _process_config_file (const std::string &config_file, bool throw_error) -> bool |
| Reads and applies one configuration file. | |
| auto | _process_env () -> void |
| Fills options from environment variables. Runs on every subcommand. | |
| auto | _process_callbacks (callback_priority_t priority) -> void |
| Runs the option callbacks at one priority. Runs on every subcommand. | |
| auto | _process_help_flags (callback_priority_t priority, bool trigger_help=false, bool trigger_all_help=false) const -> void |
| Handles any help flags that were used. | |
| auto | _process_requirements () -> void |
| Checks required options and cross-requirements, including selected subcommands. | |
| auto | _process () -> void |
| Runs every post-parse phase in order. | |
| auto | _process_extras () -> void |
| Reports anything left over that should not be. | |
| auto | increment_parsed () -> void |
| Increments the parse counter here and on nameless subcommands. | |
| auto | _parse (std::vector< std::string > &args) -> void |
| Parses a list of arguments. | |
| auto | _parse (std::vector< std::string > &&args) -> void |
| Parses a list of arguments. | |
| auto | _parse_stream (std::istream &input) -> void |
| Parses a stream as a configuration file. | |
| auto | _parse_config (const std::vector< config_item_t > &args) -> void |
| Applies a set of configuration entries. | |
| auto | _parse_single_config (const config_item_t &item, std::size_t level=0) -> bool |
| Applies one configuration entry. | |
| auto | _add_flag_like_result (option_t *op, const config_item_t &item, const std::vector< std::string > &inputs) -> bool |
| Stores a configuration entry against a flag-like option. | |
| auto | _parse_single (std::vector< std::string > &args, bool &positional_only) -> bool |
| Parses one argument, which may consume several. | |
| auto | _count_remaining_positionals (bool required_only=false) const -> std::size_t |
| Counts the positionals still waiting for values. | |
| auto | _has_remaining_positionals () const -> bool |
| Reports whether any positional is still waiting for values. | |
| auto | _parse_positional (std::vector< std::string > &args, bool halt_on_subcommand) -> bool |
| Parses a positional argument, walking up the tree as needed. | |
| auto | _find_subcommand (const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept -> app_t * |
| Finds a subcommand by name. | |
| auto | _parse_subcommand (std::vector< std::string > &args) -> bool |
| Parses a subcommand and everything it consumes. | |
| auto | _parse_arg (std::vector< std::string > &args, detail::classifier_t current_type, bool local_processing_only) -> bool |
| Parses an option argument sitting at the front of the list. | |
| auto | _trigger_pre_parse (std::size_t remaining_args) -> void |
| Runs the pre-parse callback, if it has not already run. | |
| auto | _get_fallthrough_parent () noexcept -> app_t * |
| Returns the application to fall through to. | |
| auto | _get_fallthrough_parent () const noexcept -> const app_t * |
| Returns the application to fall through to. | |
| auto | _compare_subcommand_names (const app_t &subcom, const app_t &base) const -> const std::string & |
| Returns the first name two subcommands share. | |
| auto | _move_to_missing (detail::classifier_t val_type, const std::string &val) -> void |
| Records an argument that matched nothing. | |
Protected Attributes | |
Basics | |
| std::string | name_ {} |
| Subcommand name, or program name; taken from the parser when empty. | |
| std::string | description_ {} |
| Description of this program or subcommand. | |
| extras_mode_t | allow_extras_ {extras_mode_t::error} |
| What to do with unmatched command-line arguments. Inheritable. | |
| config_extras_mode_t | allow_config_extras_ {config_extras_mode_t::ignore} |
| What to do with unmatched configuration entries. Inheritable. | |
| prefix_command_mode_t | prefix_command_ {prefix_command_mode_t::off} |
| Whether an unrecognised argument stops parsing. Inheritable. | |
| bool | has_automatic_name_ {false} |
| Whether the name was taken from the command line rather than set. | |
| bool | required_ {false} |
| Whether this subcommand must be used; ignored for the main app. | |
| bool | disabled_ {false} |
| Whether this subcommand is disabled; ignored for the main app. | |
| bool | pre_parse_called_ {false} |
| Whether pre_parse_callback_ has already fired. | |
| bool | immediate_callback_ {false} |
| Whether the callback runs on parse completion, before help and configuration files are handled. Inheritable. | |
| std::function< void(std::size_t)> | pre_parse_callback_ {} |
| Runs before parsing starts, given the argument count. | |
| std::function< void()> | parse_complete_callback_ {} |
| Runs once parsing has finished. | |
| std::function< void()> | final_callback_ {} |
| Runs once all processing has finished. | |
Options | |
| option_defaults_t | option_defaults_ {} |
| Settings newly added options inherit. Inheritable. | |
| std::vector< option_ptr_t > | options_ {} |
| The options owned by this application. | |
Config | |
| option_t * | config_ptr_ {nullptr} |
| The option naming a configuration file, if one was added. | |
| std::shared_ptr< config_t > | config_formatter_ {std::make_shared<config_toml_t>()} |
| Reads and writes configuration files. Inheritable, shared by pointer. | |
Subcommands | |
| enum class | startup_mode_t : std::uint8_t { stable , enabled , disabled } |
| Whether clear leaves this subcommand enabled or disabled. More... | |
| std::vector< app_ptr_t > | subcommands_ {} |
| The subcommands owned by this application. | |
| bool | ignore_case_ {false} |
| Whether subcommand name matching ignores case. Inheritable. | |
| bool | ignore_underscore_ {false} |
| Whether subcommand name matching ignores underscores. Inheritable. | |
| bool | fallthrough_ {false} |
| Whether options may fall through to a parent command. | |
| bool | subcommand_fallthrough_ {true} |
| Whether a later subcommand may be triggered from within this one. | |
| bool | allow_windows_style_options_ |
| Whether /opt is accepted as an option form. | |
| bool | positionals_at_end_ {false} |
| Whether positionals must come after every option. Not inheritable. | |
| startup_mode_t | default_startup {startup_mode_t::stable} |
| What clear does to this subcommand's enabled state. | |
| bool | configurable_ {false} |
| Whether this subcommand can be triggered from a configuration file. Inheritable. | |
| bool | validate_positionals_ {false} |
| Whether positionals are validated before being assigned. Inheritable. | |
| bool | validate_optional_arguments_ {false} |
| Whether optional vector arguments are validated before being assigned. Inheritable. | |
| bool | silent_ {false} |
| Whether this subcommand is hidden from the subcommand list. | |
| bool | allow_non_standard_options_ {false} |
| Whether non-standard option names such as -single_dash_flag are accepted. | |
| bool | allow_prefix_matching_ {false} |
| Whether a subcommand may be matched by a unique prefix of its name. | |
| std::uint32_t | parsed_ {0U} |
| How many times this command or subcommand has been parsed. | |
| std::size_t | require_subcommand_min_ {0} |
| Smallest number of subcommands that must be used. Not inheritable. | |
| std::size_t | require_subcommand_max_ {0} |
| Largest number of subcommands accepted; 0 is unlimited. Inheritable. | |
| std::size_t | require_option_min_ {0} |
| Smallest number of options that must be used. Not inheritable. | |
| std::size_t | require_option_max_ {0} |
| Largest number of options accepted; 0 is unlimited. Not inheritable. | |
| app_t * | parent_ {nullptr} |
| The parent application, if this is a subcommand. | |
| std::string | group_ {"SUBCOMMANDS"} |
| The help group this subcommand is listed under. Inheritable. | |
| std::vector< std::string > | aliases_ {} |
| Alternative names this subcommand answers to. | |
| auto | add_subcommand (std::string subcommand_name="", std::string subcommand_description="") -> app_t * |
| Adds a subcommand. | |
| auto | add_subcommand (app_ptr_t subcom) -> app_t * |
| Adds an already-constructed application as a subcommand. | |
| auto | remove_subcommand (app_t *subcom) -> bool |
| Removes a subcommand from this application. | |
| auto | get_subcommand (const app_t *subcom) const -> app_t * |
| Finds a subcommand by pointer. | |
| auto | get_subcommand (std::string subcom) const -> app_t * |
| Finds a subcommand by name. | |
| auto | get_subcommand_no_throw (std::string subcom) const noexcept -> app_t * |
| Finds a subcommand by name, without throwing. | |
| auto | get_subcommand (int index=0) const -> app_t * |
| Finds a subcommand by position. | |
| auto | get_subcommand_ptr (app_t *subcom) const -> app_ptr_t |
| Finds a subcommand by pointer and returns an owning handle. | |
| auto | get_subcommand_ptr (std::string subcom) const -> app_ptr_t |
| Finds a subcommand by name and returns an owning handle. | |
| auto | get_subcommand_ptr (int index=0) const -> app_ptr_t |
| Finds a subcommand by position and returns an owning handle. | |
| auto | get_option_group (std::string group_name) const -> app_t * |
| Finds an option group by name. | |
| auto | count () const -> std::size_t |
| Returns how many times this subcommand was used. | |
| auto | count_all () const -> std::size_t |
| Returns how many arguments were consumed by options and subcommands. | |
| auto | group (std::string group_name) -> app_t * |
| Sets the help group this subcommand is listed under. | |
| auto | require_subcommand () -> app_t * |
| Requires at least one subcommand to be used. | |
| auto | require_subcommand (int value) -> app_t * |
| Requires a given number of subcommands. | |
| auto | require_subcommand (std::size_t min, std::size_t max) -> app_t * |
| Requires a number of subcommands within a range. | |
| auto | require_option () -> app_t * |
| Requires at least one option to be used. | |
| auto | require_option (int value) -> app_t * |
| Requires a given number of options. | |
| auto | require_option (std::size_t min, std::size_t max) -> app_t * |
| Requires a number of options within a range. | |
| auto | fallthrough (bool value=true) -> app_t * |
| Lets unrecognised options fall through to the parent command. | |
| auto | subcommand_fallthrough (bool value=true) -> app_t * |
| Lets a parent's subcommands be recognised from within this one. | |
| operator bool () const | |
| Reports whether this subcommand appeared on the command line. | |
Parsing | |
| using | missing_t = std::vector<std::pair<detail::classifier_t, std::string>> |
| Arguments that matched nothing, paired with how they were classified. | |
| missing_t | missing_ {} |
| Arguments that matched nothing. Extra detail is stripped on return from parse. | |
| std::vector< option_t * > | parse_order_ {} |
| The options that were used, in the order they appeared. | |
| std::vector< app_t * > | parsed_subcommands_ {} |
| The subcommands that were used, in the order they appeared. | |
| std::set< app_t * > | exclude_subcommands_ {} |
| Subcommands that may not be used alongside this one. | |
| std::set< option_t * > | exclude_options_ {} |
| Options that may not be used alongside this subcommand. | |
| std::set< app_t * > | need_subcommands_ {} |
| Subcommands this one requires. Not mutual: they do not require this one. | |
| std::set< option_t * > | need_options_ {} |
| Options this subcommand requires. Not mutual. | |
| auto | clear () -> void |
| Discards everything collected by a previous parse. | |
| auto | parse (int argc, const char *const *argv) -> void |
| Parses the command line. | |
| auto | parse (int argc, const wchar_t *const *argv) -> void |
| Parses a wide command line. | |
| auto | parse (std::string commandline, bool program_name_included=false) -> void |
| Parses a whole command line held in one string. | |
| auto | parse (std::wstring commandline, bool program_name_included=false) -> void |
| Parses a whole wide command line held in one string. | |
| auto | parse (std::vector< std::string > &args) -> void |
| Parses a list of arguments, in reverse order. | |
| auto | parse (std::vector< std::string > &&args) -> void |
| Parses a list of arguments, in reverse order. | |
| auto | parse_from_stream (std::istream &input) -> void |
| Parses arguments read from a stream as a configuration file. | |
| auto | failure_message (std::function< std::string(const app_t *, const error_t &)> function) -> void |
| Sets how an error is rendered by exit. | |
| auto | exit (const error_t &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const -> int |
| Prints an error and returns the exit code to give the process. | |
Getters | |
| enum class | name_match_t : std::uint8_t { none = 0 , exact = 1 , prefix = 2 } |
| How closely a name matched. More... | |
| auto | get_formatter () const -> std::shared_ptr< formatter_base_t > |
| Returns the help formatter. | |
| auto | get_config_formatter () const -> std::shared_ptr< config_t > |
| Returns the configuration reader and writer. | |
| auto | get_config_formatter_base () const -> std::shared_ptr< config_base_t > |
| Returns the configuration converter as a config_base_t. | |
| auto | get_description () const -> const std::string & |
| Returns the description shown in help output. | |
| auto | description (std::string app_description) -> app_t * |
| Sets the description shown in help output. | |
| auto | get_options (const std::function< bool(const option_t *)> &filter={}) const -> std::vector< const option_t * > |
| Returns the options matching a filter. | |
| auto | get_options (const std::function< bool(option_t *)> &filter={}) -> std::vector< option_t * > |
| Returns the options matching a filter. | |
| auto | get_option_no_throw (std::string option_name) noexcept -> option_t * |
| Finds an option by name, without throwing. | |
| auto | get_option_no_throw (std::string option_name) const noexcept -> const option_t * |
| Finds an option by name, without throwing. | |
| auto | get_option (std::string option_name) const -> const option_t * |
| Finds an option by name. | |
| auto | get_option (std::string option_name) -> option_t * |
| Finds an option by name. | |
| auto | operator[] (const std::string &option_name) const -> const option_t * |
| Finds an option by name. | |
| auto | operator[] (const char *option_name) const -> const option_t * |
| Finds an option by name. | |
| auto | get_ignore_case () const -> bool |
| Reports whether name matching ignores case. | |
| auto | get_ignore_underscore () const -> bool |
| Reports whether name matching ignores underscores. | |
| auto | get_fallthrough () const -> bool |
| Reports whether options fall through to the parent command. | |
| auto | get_subcommand_fallthrough () const -> bool |
| Reports whether a parent's subcommands are recognised here. | |
| auto | get_allow_windows_style_options () const -> bool |
| Reports whether Windows-style options are accepted. | |
| auto | get_positionals_at_end () const -> bool |
| Reports whether positionals must appear after every option. | |
| auto | get_configurable () const -> bool |
| Reports whether this subcommand can be triggered from a configuration file. | |
| auto | get_group () const -> const std::string & |
| Returns the help group this subcommand is listed under. | |
| auto | get_usage () const -> std::string |
| Returns the usage line. | |
| auto | get_footer () const -> std::string |
| Returns the footer. | |
| auto | get_require_subcommand_min () const -> std::size_t |
| Returns the smallest number of subcommands that must be used. | |
| auto | get_require_subcommand_max () const -> std::size_t |
| Returns the largest number of subcommands accepted. | |
| auto | get_require_option_min () const -> std::size_t |
| Returns the smallest number of options that must be used. | |
| auto | get_require_option_max () const -> std::size_t |
| Returns the largest number of options accepted. | |
| auto | get_prefix_command () const -> bool |
| Reports whether parsing stops at an unrecognised argument. | |
| auto | get_prefix_command_mode () const -> prefix_command_mode_t |
| Returns when parsing stops early. | |
| auto | get_allow_extras () const -> bool |
| Reports whether unmatched arguments are accepted. | |
| auto | get_allow_extras_mode () const -> extras_mode_t |
| Returns what happens to unmatched arguments. | |
| auto | get_required () const -> bool |
| Reports whether this subcommand must be used. | |
| auto | get_disabled () const -> bool |
| Reports whether this subcommand is disabled. | |
| auto | get_silent () const -> bool |
| Reports whether this subcommand is hidden from the processed list. | |
| auto | get_allow_non_standard_option_names () const -> bool |
| Reports whether non-standard option names are accepted. | |
| auto | get_allow_subcommand_prefix_matching () const -> bool |
| Reports whether subcommands may be matched by a name prefix. | |
| auto | get_immediate_callback () const -> bool |
| Reports whether the callback runs as soon as parsing finishes. | |
| auto | get_disabled_by_default () const -> bool |
| Reports whether clear leaves this subcommand disabled. | |
| auto | get_enabled_by_default () const -> bool |
| Reports whether clear leaves this subcommand enabled. | |
| auto | get_validate_positionals () const -> bool |
| Reports whether positionals are validated before assignment. | |
| auto | get_validate_optional_arguments () const -> bool |
| Reports whether optional vector arguments are validated before assignment. | |
| auto | get_allow_config_extras () const -> config_extras_mode_t |
| Returns what happens to unmatched configuration entries. | |
| auto | get_help_ptr () -> option_t * |
| Returns the help flag. | |
| auto | get_help_ptr () const -> const option_t * |
| Returns the help flag. | |
| auto | get_help_all_ptr () const -> const option_t * |
| Returns the expanded-help flag. | |
| auto | get_config_ptr () -> option_t * |
| Returns the option naming a configuration file. | |
| auto | get_config_ptr () const -> const option_t * |
| Returns the option naming a configuration file. | |
| auto | get_version_ptr () -> option_t * |
| Returns the version flag. | |
| auto | get_version_ptr () const -> const option_t * |
| Returns the version flag. | |
| auto | get_parent () -> app_t * |
| Returns the parent application. | |
| auto | get_parent () const -> const app_t * |
| Returns the parent application. | |
| auto | get_name () const -> const std::string & |
| Returns this application's name. | |
| auto | get_aliases () const -> const std::vector< std::string > & |
| Returns the alternative names this subcommand answers to. | |
| auto | clear_aliases () -> app_t * |
| Removes every alias. | |
| auto | get_display_name (bool with_aliases=false) const -> std::string |
| Returns the name shown in help output. | |
| auto | check_name (std::string name_to_check) const -> bool |
| Reports whether a name refers to this subcommand. | |
| auto | check_name_detail (std::string name_to_check) const -> name_match_t |
| Reports how closely a name matches this subcommand. | |
| auto | get_groups () const -> std::vector< std::string > |
| Returns the option groups defined here, in definition order. | |
| auto | parse_order () const -> const std::vector< option_t * > & |
| Returns the options that were used, in command-line order. | |
| auto | remaining (bool recurse=false) const -> std::vector< std::string > |
| Returns the arguments that matched nothing. | |
| auto | remaining_for_passthrough (bool recurse=false) const -> std::vector< std::string > |
| Returns the unmatched arguments, ready to hand to another program. | |
| auto | remaining_size (bool recurse=false) const -> std::size_t |
| Returns how many arguments matched nothing, excluding the -- separator. | |
Help | |
| std::string | usage_ {} |
| Usage line placed after the description. Inheritable. | |
| std::function< std::string()> | usage_callback_ {} |
| Generates the usage line, when one is not set directly. | |
| std::string | footer_ {} |
| Footer placed after all options. Inheritable. | |
| std::function< std::string()> | footer_callback_ {} |
| Generates the footer, when one is not set directly. | |
| option_t * | help_ptr_ {nullptr} |
| The help option, if one was added. Inheritable. | |
| option_t * | help_all_ptr_ {nullptr} |
| The expanded-help option, if one was added. Inheritable. | |
| option_t * | version_ptr_ {nullptr} |
| The version option, if one was added. | |
| std::shared_ptr< formatter_base_t > | formatter_ {std::make_shared<formatter_t>()} |
| Renders help output. Inheritable, and shared by pointer. | |
| std::function< std::string(const app_t *, const error_t &)> | failure_message_ |
| Renders an error into the message printed by exit. Inheritable. | |
| auto | usage (std::string usage_string) -> app_t * |
| Sets the usage line shown after the description. | |
| auto | usage (std::function< std::string()> usage_function) -> app_t * |
| Sets a callable producing the usage line. | |
| auto | footer (std::string footer_string) -> app_t * |
| Sets the footer shown after all options. | |
| auto | footer (std::function< std::string()> footer_function) -> app_t * |
| Sets a callable producing the footer. | |
| auto | config_to_str () const -> std::string |
| Writes the current values out as configuration text. | |
| auto | config_to_str (config_output_mode_t mode, bool write_description=false) const -> std::string |
| Writes the current values out as configuration text. | |
| auto | config_to_str (bool default_also, bool write_description=false) const -> std::string |
| Writes the current values out as configuration text. | |
| auto | help (std::string prev="", app_format_mode_t mode=app_format_mode_t::normal) const -> std::string |
| Renders the help page using the configured formatter. | |
| auto | version () const -> std::string |
| Renders the version string. | |
Adding options | |
| auto | add_option (std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={}) -> option_t * |
| Adds an option driven by a callback. | |
| template<typename assign_to_t, typename convert_to_t = assign_to_t> requires (!std::is_const_v<convert_to_t>) | |
| auto | add_option (std::string option_name, assign_to_t &variable, std::string option_description="") -> option_t * |
| Adds an option bound to a variable. | |
| template<typename assign_to_t> requires (!std::is_const_v<assign_to_t>) | |
| auto | add_option_no_stream (std::string option_name, assign_to_t &variable, std::string option_description="") -> option_t * |
| Adds an option bound to a variable, without a printed default. | |
| template<typename arg_type_t> | |
| auto | add_option_function (std::string option_name, std::function< void(const arg_type_t &)> func, std::string option_description="") -> option_t * |
| Adds an option that hands its converted value to a callback. | |
| auto | add_option (std::string option_name) -> option_t * |
| Adds an option with no description and no bound variable. | |
| template<typename T> requires (std::is_const_v<T> && std::is_constructible_v<std::string, T>) | |
| auto | add_option (std::string option_name, T &option_description) -> option_t * |
| Adds an option with a description but no bound variable. | |
| auto | set_help_flag (std::string flag_name="", const std::string &help_description="") -> option_t * |
| Replaces the help flag. | |
| auto | set_help_all_flag (std::string help_name="", const std::string &help_description="") -> option_t * |
| Replaces the expanded-help flag. | |
| auto | set_version_flag (std::string flag_name="", const std::string &version_string="", const std::string &version_help="Display program version information and exit") -> option_t * |
| Replaces the version flag with a fixed version string. | |
| auto | set_version_flag (std::string flag_name, std::function< std::string()> vfunc, const std::string &version_help="Display program version information and exit") -> option_t * |
| Replaces the version flag with one that generates its text. | |
| auto | add_flag (std::string flag_name) -> option_t * |
| Adds a flag with no description and no bound variable. | |
| template<typename T> requires ((std::is_const_v<std::remove_reference_t<T>> || std::is_rvalue_reference_v<T &&>) && std::is_constructible_v <std::string, std::remove_reference_t<T>>) | |
| auto | add_flag (std::string flag_name, T &&flag_description) -> option_t * |
| Adds a flag with a description but no bound variable. | |
| template<typename T> requires (!detail::mutable_container<T> && !std::is_const_v<T> && !std::is_constructible_v<std::function<void(std::int64_t)>, T>) | |
| auto | add_flag (std::string flag_name, T &flag_result, std::string flag_description="") -> option_t * |
| Adds a flag bound to a variable. | |
| template<typename T> requires (!std::is_assignable_v<std::function<void(std::int64_t)> &, T>) | |
| auto | add_flag (std::string flag_name, std::vector< T > &flag_results, std::string flag_description="") -> option_t * |
| Adds a flag that collects a value for every appearance. | |
| auto | add_flag_callback (std::string flag_name, std::function< void()> function, std::string flag_description="") -> option_t * |
| Adds a flag that calls a function taking no arguments. | |
| auto | add_flag_function (std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="") -> option_t * |
| Adds a flag that calls a function with its accumulated count. | |
| auto | add_flag (std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="") -> option_t * |
| Adds a flag that calls a function with its accumulated count. | |
| auto | set_config (std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false) -> option_t * |
| Sets the option that names a configuration file. | |
| auto | remove_option (option_t *opt) -> bool |
| Removes an option from this application. | |
| template<typename T = option_group_t> | |
| auto | add_option_group (std::string group_name, std::string group_description="") -> T * |
| Adds an option group. | |
A command-line parser, a subcommand, or an option group.
Create one, add options to it, and call parse. Call exit from a catch block to turn a cli::parse_error_t into a process exit code.
|
protected |
Arguments that matched nothing, paired with how they were classified.
Keeping the classification avoids reclassifying on the way back out. May contain the -- separator.
|
strong |
|
strongprotected |
Whether clear leaves this subcommand enabled or disabled.
| Enumerator | |
|---|---|
| stable | Leave the enabled state as it is. |
| enabled | Enable at the start of each parse. |
| disabled | Disable at the start of each parse. |
|
protected |
Constructs a subcommand.
| app_description | The description shown in help output. |
| app_name | The subcommand name. |
| parent | The owning application. |
|
inlineexplicit |
Constructs a top-level application.
A -h,--help flag is added automatically; remove it with set_help_flag if you want to supply your own.
| app_description | The description shown in help output. |
| app_name | The program name; taken from the command line when empty. |
|
protected |
Stores a configuration entry against a flag-like option.
| op | The option to fill. |
| item | The entry being applied. |
| inputs | The values from the entry. |
|
nodiscardprotected |
Returns the first name two subcommands share.
| subcom | The subcommand being added. |
| base | The subcommand to compare against. |
|
protected |
Prepares the subcommand tree for parsing.
Sets fallthrough and prefix behaviour on nameless subcommands, applies the automatic enable or disable, and fixes up parent pointers.
|
nodiscardprotected |
Counts the positionals still waiting for values.
| required_only | Count only the required ones. |
|
nodiscardprotectednoexcept |
Finds a subcommand by name.
| subc_name | The name to look for. |
| ignore_disabled | Skip disabled subcommands. |
| ignore_used | Skip subcommands that were already used. |
|
nodiscardprotectednoexcept |
Returns the application to fall through to.
|
nodiscardprotectednoexcept |
Returns the application to fall through to.
The nearest named ancestor, or the main application.
|
nodiscardprotected |
Reports whether any positional is still waiting for values.
| auto cli::app_t::_move_option | ( | option_t * | opt, |
| app_t * | app ) -> void |
Moves an option from one application to another.
Provided for subclasses that reorganise options into subcommands.
| opt | The option to move. |
| app | The application to move it to. |
|
protected |
Records an argument that matched nothing.
| val_type | How the argument was classified. |
| val | The argument itself. |
|
protected |
Parses a list of arguments.
| args | The arguments, last one first. |
|
protected |
Parses a list of arguments.
| [in,out] | args | The arguments, last one first. |
|
protected |
Parses an option argument sitting at the front of the list.
| [in,out] | args | The remaining arguments, last one first. |
| [in] | current_type | How the leading argument was classified. |
| [in] | local_processing_only | Disable fallthrough, reporting failure instead. |
|
protected |
Applies a set of configuration entries.
An entry whose name contains a separator is routed into the matching subcommand.
| args | The entries to apply. |
|
protected |
Parses a positional argument, walking up the tree as needed.
| [in,out] | args | The remaining arguments, last one first. |
| [in] | halt_on_subcommand | Return false rather than descending into a subcommand. |
|
protected |
Parses one argument, which may consume several.
Delegates to the parent on failure, and records the argument as missing if even the main application cannot place it.
| [in,out] | args | The remaining arguments, last one first. |
| [in,out] | positional_only | Whether the -- separator has been seen. |
|
protected |
Applies one configuration entry.
| item | The entry to apply. |
| level | How many section levels have been descended. |
|
protected |
Parses a stream as a configuration file.
| input | The stream to read. |
|
protected |
Parses a subcommand and everything it consumes.
Always allows fallthrough, unlike the other parse helpers.
| [in,out] | args | The remaining arguments, last one first. |
|
protected |
Runs the option callbacks at one priority. Runs on every subcommand.
| priority | Which callbacks to run. |
|
protected |
Reads and applies one configuration file.
| config_file | The path to read. |
| throw_error | Report an error when the file cannot be read. |
|
protected |
Handles any help flags that were used.
The flags let a recursive call remember that a parent already saw one.
| priority | Which callbacks are being run. |
| trigger_help | Whether a parent saw the help flag. |
| trigger_all_help | Whether a parent saw the expanded-help flag. |
|
nodiscardprotected |
Classifies one command-line argument.
| current | The argument to classify. |
| ignore_used_subcommands | Skip subcommands that were already used. |
|
protected |
Runs the pre-parse callback, if it has not already run.
| remaining_args | How many arguments are left to parse. |
|
nodiscardprotected |
Reports whether a token names a usable subcommand.
Gives up immediately once the subcommand maximum has been reached.
| current | The token to test. |
| ignore_used | Skip subcommands that were already used. |
|
protected |
Checks the option set for conflicts.
Looks for more than one positional taking unlimited arguments, and for minimum and maximum counts that cannot both be satisfied.
| cli::invalid_error_t | If the option set cannot work. |
|
inline |
Adds a flag with no description and no bound variable.
| flag_name | The name specification. |
|
inline |
Adds a flag that calls a function with its accumulated count.
Aliases add_flag_function.
| flag_name | The name specification. |
| function | Called with the flag's value. |
| flag_description | The description shown in help output. |
|
inline |
Adds a flag that collects a value for every appearance.
| T | The element type of the bound vector. |
| flag_name | The name specification. |
| flag_results | The vector to append to. |
| flag_description | The description shown in help output. |
|
inline |
Adds a flag with a description but no bound variable.
Takes a const string or an rvalue string. A non-const lvalue string binds to the overload below instead, and receives the flag's result.
| T | A const or rvalue string-like type. |
| flag_name | The name specification. |
| flag_description | The description shown in help output. |
|
inline |
Adds a flag bound to a variable.
Accepts anything that is not a container and not callable: bool, an enumeration, a string, an integer counter, or any type constructible from a string. An integer wider than a byte is treated as a counter.
| T | The type of the bound variable. |
| flag_name | The name specification. |
| flag_result | The variable to fill. |
| flag_description | The description shown in help output. |
| auto cli::app_t::add_flag_callback | ( | std::string | flag_name, |
| std::function< void()> | function, | ||
| std::string | flag_description = "" ) -> option_t * |
Adds a flag that calls a function taking no arguments.
| flag_name | The name specification. |
| function | Called once when the flag is used. |
| flag_description | The description shown in help output. |
| auto cli::app_t::add_flag_function | ( | std::string | flag_name, |
| std::function< void(std::int64_t)> | function, | ||
| std::string | flag_description = "" ) -> option_t * |
Adds a flag that calls a function with its accumulated count.
| flag_name | The name specification. |
| function | Called with the flag's value. |
| flag_description | The description shown in help output. |
|
inline |
Adds an option with no description and no bound variable.
| option_name | The name specification. |
|
inline |
Adds an option bound to a variable.
The variable's type determines how many values the option takes and how they are converted. Supply convert_to_t when the value should be read as one type and stored as another.
| assign_to_t | The type of the bound variable. |
| convert_to_t | The type values are parsed as. |
| option_name | The name specification. |
| variable | The variable to fill. |
| option_description | The description shown in help output. |
| auto cli::app_t::add_option | ( | std::string | option_name, |
| callback_t | option_callback, | ||
| std::string | option_description = "", | ||
| bool | defaulted = false, | ||
| std::function< std::string()> | func = {} ) -> option_t * |
Adds an option driven by a callback.
The other add_option overloads build on this one.
| option_name | The name specification, for example "-f,--file". |
| option_callback | Consumes the collected results. |
| option_description | The description shown in help output. |
| defaulted | Whether the bound value already holds a usable default. |
| func | Produces the printed default. |
|
inline |
Adds an option with a description but no bound variable.
| T | A const string-like type. |
| option_name | The name specification. |
| option_description | The description shown in help output. |
|
inline |
Adds an option that hands its converted value to a callback.
| arg_type_t | The type values are converted to. |
| option_name | The name specification. |
| func | Receives the converted value. |
| option_description | The description shown in help output. |
|
inline |
Adds an option group.
An option group is a subcommand with no name: it groups options in help output and can carry its own requirements, but is never named on the command line.
| T | The group type to create. |
| group_name | The group name. |
| group_description | The description shown in help output. |
| cli::incorrect_construction_t | If group_name contains a newline or null character. |
|
inline |
Adds an option bound to a variable, without a printed default.
For types that have no usable string representation.
| assign_to_t | The type of the bound variable. |
| option_name | The name specification. |
| variable | The variable to fill. |
| option_description | The description shown in help output. |
Adds an already-constructed application as a subcommand.
| subcom | The subcommand to adopt. |
| auto cli::app_t::add_subcommand | ( | std::string | subcommand_name = "", |
| std::string | subcommand_description = "" ) -> app_t * |
Adds a subcommand.
The subcommand inherits the inheritable settings and the option defaults.
| subcommand_name | The subcommand name. |
| subcommand_description | The description shown in help output. |
| auto cli::app_t::alias | ( | std::string | app_name | ) | -> app_t * |
Adds an alternative name this subcommand answers to.
| app_name | The alias. |
|
inline |
Accepts unmatched configuration entries instead of reporting them.
Enabling this also enables allow_extras, since a captured configuration entry has to go somewhere.
| allow | Whether to accept them. |
|
inline |
Sets what happens to unmatched configuration entries.
| mode | The mode to use. |
|
inline |
Accepts unmatched arguments instead of reporting them.
| allow | Whether to accept them. |
|
inline |
Sets what happens to unmatched arguments.
| allow | The mode to use. |
|
inline |
Accepts non-standard option names such as -single_dash_flag.
| allowed | Whether to accept them. |
|
inline |
Lets a subcommand be matched by a unique prefix of its name.
| allowed | Whether to allow prefix matching. |
|
inline |
Accepts Windows-style options such as /opt.
The first matching short or long name wins. Subcommands inherit this.
| value | Whether to accept them. |
|
inline |
Sets the callback run once everything has been parsed and processed.
Assigns to parse_complete_callback when immediate_callback is set, and to final_callback otherwise. Capture by reference if the callback needs the application itself.
| app_callback | The callback to run. |
|
nodiscard |
Reports whether a name refers to this subcommand.
Honours the case, underscore, and prefix-matching settings.
| name_to_check | The name to test. |
|
nodiscard |
Reports how closely a name matches this subcommand.
Honours the case and underscore settings.
| name_to_check | The name to test. |
|
inline |
Removes every alias.
Replaces the configuration reader and writer.
| fmt | The converter to use. |
|
inlinenodiscard |
Writes the current values out as configuration text.
|
inlinenodiscard |
Writes the current values out as configuration text.
| default_also | Include options left at their defaults. |
| write_description | Include descriptions as comments. |
|
inlinenodiscard |
Writes the current values out as configuration text.
| mode | How much of the application to write. |
| write_description | Include descriptions as comments. |
|
inline |
Lets this subcommand be triggered from a configuration file.
| value | Whether the subcommand is configurable. |
|
inlinenodiscard |
Returns how many times this subcommand was used.
The main application reports 1, as does an unnamed subcommand unless a callback changes it.
|
inlinenodiscard |
Returns how many times an option was used.
| option_name | The option to look up. |
| cli::option_not_found_t | If no option matches. |
|
nodiscard |
Returns how many arguments were consumed by options and subcommands.
Arguments treated as extras are not counted.
|
inline |
Sets the description shown in help output.
| app_description | The description. |
|
inline |
Disables this subcommand or option group.
| disable | Whether to disable it. |
|
inline |
Makes clear leave this subcommand disabled.
Turning this off returns to the stable state unless enabled_by_default was set, which takes precedence.
| disable | Whether to disable by default. |
|
inline |
Makes clear leave this subcommand enabled.
Turning this off returns to the stable state unless disabled_by_default was set, which takes precedence.
| enable | Whether to enable by default. |
|
nodiscard |
Converts argv to UTF-8 on Windows; does nothing elsewhere.
The converted strings are owned by this application, so the returned pointer stays valid for as long as it does.
| argv | The argument array from main. |
Forbids a subcommand from being used alongside this one.
The exclusion is recorded on both subcommands.
| app | The subcommand to exclude. |
| cli::option_not_found_t | If app is null or is this application. |
|
inline |
Forbids an option from being used alongside this subcommand.
| opt | The option to exclude. |
| cli::option_not_found_t | If opt is null. |
| auto cli::app_t::exit | ( | const error_t & | e, |
| std::ostream & | out = std::cout, | ||
| std::ostream & | err = std::cerr ) const -> int |
Prints an error and returns the exit code to give the process.
A help or version request is printed to out; anything else goes to err.
| e | The error to report. |
| out | The stream used for successful early exits. |
| err | The stream used for failures. |
|
inline |
Sets how an error is rendered by exit.
| function | Receives the application and the error, returns the text to print. |
|
inline |
Lets unrecognised options fall through to the parent command.
Inherited from the parent, and usually set there.
| value | Whether to allow fallthrough. |
|
inline |
Sets the callback run once everything has been processed.
| app_callback | The callback to run. |
|
inline |
Sets a callable producing the footer.
| footer_function | Produces the footer text. |
|
inline |
Sets the footer shown after all options.
| footer_string | The footer text. |
|
inline |
Replaces the help formatter.
| fmt | The formatter to use. |
|
inline |
Replaces the help formatter with a callable.
| fmt | Renders the whole help page. |
|
inlinenodiscard |
Returns the alternative names this subcommand answers to.
|
inlinenodiscard |
Returns what happens to unmatched configuration entries.
|
inlinenodiscard |
Reports whether unmatched arguments are accepted.
|
inlinenodiscard |
Returns what happens to unmatched arguments.
|
inlinenodiscard |
Reports whether non-standard option names are accepted.
|
inlinenodiscard |
Reports whether subcommands may be matched by a name prefix.
|
inlinenodiscard |
Reports whether Windows-style options are accepted.
|
inlinenodiscard |
Returns the configuration reader and writer.
|
inlinenodiscard |
Returns the configuration converter as a config_base_t.
|
inlinenodiscard |
Returns the option naming a configuration file.
|
inlinenodiscard |
Returns the option naming a configuration file.
|
inlinenodiscard |
Reports whether this subcommand can be triggered from a configuration file.
|
inlinenodiscard |
Returns the description shown in help output.
|
inlinenodiscard |
Reports whether this subcommand is disabled.
|
inlinenodiscard |
Reports whether clear leaves this subcommand disabled.
|
nodiscard |
Returns the name shown in help output.
| with_aliases | Include the aliases alongside the name. |
|
inlinenodiscard |
Reports whether clear leaves this subcommand enabled.
|
inlinenodiscard |
Reports whether options fall through to the parent command.
|
inlinenodiscard |
Returns the footer.
When a footer callback is set, its output precedes any fixed footer text.
|
inlinenodiscard |
Returns the help formatter.
|
inlinenodiscard |
Returns the help group this subcommand is listed under.
|
nodiscard |
Returns the option groups defined here, in definition order.
|
inlinenodiscard |
Returns the expanded-help flag.
|
inlinenodiscard |
Returns the help flag.
|
inlinenodiscard |
Returns the help flag.
|
inlinenodiscard |
Reports whether name matching ignores case.
|
inlinenodiscard |
Reports whether name matching ignores underscores.
|
inlinenodiscard |
Reports whether the callback runs as soon as parsing finishes.
|
inlinenodiscard |
Returns this application's name.
|
nodiscard |
Finds an option by name.
| option_name | The name to look for. |
| cli::option_not_found_t | If no option matches. |
|
nodiscard |
Finds an option by name.
| option_name | The name to look for. |
| cli::option_not_found_t | If no option matches. |
|
nodiscard |
Finds an option group by name.
| group_name | The group name. |
| cli::option_not_found_t | If no group matches. |
|
nodiscardnoexcept |
Finds an option by name, without throwing.
| option_name | The name to look for. |
|
nodiscardnoexcept |
Finds an option by name, without throwing.
| option_name | The name to look for. |
|
nodiscard |
Returns the options matching a filter.
| filter | Selects which options to return; empty returns all. |
|
nodiscard |
Returns the options matching a filter.
| filter | Selects which options to return; empty returns all. |
|
inlinenodiscard |
Returns the parent application.
|
inlinenodiscard |
Returns the parent application.
|
inlinenodiscard |
Reports whether positionals must appear after every option.
|
inlinenodiscard |
Reports whether parsing stops at an unrecognised argument.
|
inlinenodiscard |
Returns when parsing stops early.
|
inlinenodiscard |
Returns the largest number of options accepted.
|
inlinenodiscard |
Returns the smallest number of options that must be used.
|
inlinenodiscard |
Returns the largest number of subcommands accepted.
|
inlinenodiscard |
Returns the smallest number of subcommands that must be used.
|
inlinenodiscard |
Reports whether this subcommand must be used.
|
inlinenodiscard |
Reports whether this subcommand is hidden from the processed list.
Finds a subcommand by pointer.
| subcom | The subcommand to look for; nullptr returns the first one. |
| cli::option_not_found_t | If it is not a subcommand of this application. |
|
nodiscard |
Finds a subcommand by position.
| index | The position to look up. |
| cli::option_not_found_t | If index is out of range. |
|
nodiscard |
Finds a subcommand by name.
| subcom | The name to look for. |
| cli::option_not_found_t | If no subcommand matches. |
|
inlinenodiscard |
Reports whether a parent's subcommands are recognised here.
|
nodiscardnoexcept |
Finds a subcommand by name, without throwing.
| subcom | The name to look for. |
Finds a subcommand by pointer and returns an owning handle.
| subcom | The subcommand to look for. |
| cli::option_not_found_t | If it is not a subcommand of this application. |
|
nodiscard |
Finds a subcommand by position and returns an owning handle.
| index | The position to look up. |
| cli::option_not_found_t | If index is out of range. |
|
nodiscard |
Finds a subcommand by name and returns an owning handle.
| subcom | The name to look for. |
| cli::option_not_found_t | If no subcommand matches. |
|
inlinenodiscard |
Returns the subcommands that were used, in command-line order.
| auto cli::app_t::get_subcommands | ( | const std::function< bool(app_t *)> & | filter | ) | -> std::vector< app_t * > |
Returns the subcommands matching a filter, as defined.
| filter | Selects which subcommands to return; empty returns all. |
| auto cli::app_t::get_subcommands | ( | const std::function< bool(const app_t *)> & | filter | ) | const -> std::vector< const app_t * > |
Returns the subcommands matching a filter, as defined.
| filter | Selects which subcommands to return; empty returns all. |
|
inlinenodiscard |
Returns the usage line.
When a usage callback is set, its output precedes any fixed usage text.
|
inlinenodiscard |
Reports whether optional vector arguments are validated before assignment.
|
inlinenodiscard |
Reports whether positionals are validated before assignment.
|
inlinenodiscard |
Returns the version flag.
|
inlinenodiscard |
Returns the version flag.
|
inline |
Reports whether a subcommand was used.
| subcom | The subcommand to check. |
| cli::option_not_found_t | If it is not a subcommand of this application. |
|
inlinenodiscardnoexcept |
Reports whether a named subcommand was used.
| subcommand_name | The subcommand to check. |
|
inline |
Sets the help group this subcommand is listed under.
| group_name | The group name. |
|
nodiscard |
Renders the help page using the configured formatter.
Covers one subcommand at a time.
| prev | The name to present this application under. |
| mode | How much detail to include. |
| auto cli::app_t::ignore_case | ( | bool | value = true | ) | -> app_t * |
Makes name matching case-insensitive. Subcommands inherit this.
| value | Whether to ignore case. |
| auto cli::app_t::ignore_underscore | ( | bool | value = true | ) | -> app_t * |
Makes name matching ignore underscores. Subcommands inherit this.
| value | Whether to ignore underscores. |
| auto cli::app_t::immediate_callback | ( | bool | immediate = true | ) | -> app_t * |
Runs this subcommand's callback as soon as it finishes parsing.
| immediate | Whether to run the callback immediately. |
| auto cli::app_t::name | ( | std::string | app_name = "" | ) | -> app_t * |
Sets the application or subcommand name.
| app_name | The name; an empty string defers to the command line. |
Requires a subcommand to be used alongside this one.
Not mutual.
| app | The required subcommand. |
| cli::option_not_found_t | If app is null or is this application. |
|
inline |
Requires an option to be used alongside this subcommand.
Not mutual: the option does not come to require this subcommand.
| opt | The required option. |
| cli::option_not_found_t | If opt is null. |
|
inlineexplicitnodiscard |
Reports whether this subcommand appeared on the command line.
Lets a subcommand be tested directly: if (*sub) { ... }.
|
inlinenodiscard |
Finds an option by name.
| option_name | The name to look for. |
| cli::option_not_found_t | If no option matches. |
|
inlinenodiscard |
Finds an option by name.
| option_name | The name to look for. |
| cli::option_not_found_t | If no option matches. |
|
inline |
Returns the settings newly added options inherit.
| auto cli::app_t::parse | ( | int | argc, |
| const char *const * | argv ) -> void |
Parses the command line.
Call once every option and subcommand has been added.
| argc | The argument count, as given to main. |
| argv | The argument array, as given to main. |
| cli::parse_error_t | If the command line cannot be parsed. |
| auto cli::app_t::parse | ( | int | argc, |
| const wchar_t *const * | argv ) -> void |
Parses a wide command line.
The arguments are narrowed to UTF-8 first.
| argc | The argument count. |
| argv | The argument array. |
| cli::parse_error_t | If the command line cannot be parsed. |
| auto cli::app_t::parse | ( | std::string | commandline, |
| bool | program_name_included = false ) -> void |
Parses a whole command line held in one string.
The string is split into arguments and handed to the vector overload.
| commandline | The command line to parse. |
| program_name_included | Whether commandline starts with the program name. |
| cli::parse_error_t | If the command line cannot be parsed. |
| auto cli::app_t::parse | ( | std::vector< std::string > && | args | ) | -> void |
Parses a list of arguments, in reverse order.
| args | The arguments, last one first. |
| cli::parse_error_t | If the arguments cannot be parsed. |
| auto cli::app_t::parse | ( | std::vector< std::string > & | args | ) | -> void |
Parses a list of arguments, in reverse order.
This is where the work happens; the other overloads funnel into it. args is left holding whatever was not consumed.
| [in,out] | args | The arguments, last one first. |
| cli::parse_error_t | If the arguments cannot be parsed. |
| auto cli::app_t::parse | ( | std::wstring | commandline, |
| bool | program_name_included = false ) -> void |
Parses a whole wide command line held in one string.
| commandline | The command line to parse. |
| program_name_included | Whether commandline starts with the program name. |
| cli::parse_error_t | If the command line cannot be parsed. |
|
inline |
Sets the callback run once parsing has finished.
| pc_callback | The callback to run. |
| auto cli::app_t::parse_from_stream | ( | std::istream & | input | ) | -> void |
Parses arguments read from a stream as a configuration file.
| input | The stream to read. |
| cli::parse_error_t | If the contents cannot be parsed. |
|
inlinenodiscard |
Returns the options that were used, in command-line order.
|
inlinenodiscard |
Reports whether this subcommand appeared on the command line.
|
inline |
Requires positionals to appear after every option.
| value | Whether positionals come last. |
|
inlinevirtual |
Hook run after parsing but before the callbacks.
Does not run if an error or a help request was thrown.
|
inline |
Stops parsing at the first unrecognised argument.
Everything from that point on is left in the remaining-arguments list.
| is_prefix | Whether to stop early. |
|
inline |
Sets when parsing stops early.
| mode | The mode to use. |
|
inline |
Sets the callback run before parsing starts.
| pp_callback | The callback to run, given the argument count. |
|
nodiscard |
Returns the arguments that matched nothing.
| recurse | Include the arguments left over by subcommands. |
|
nodiscard |
Returns the unmatched arguments, ready to hand to another program.
| recurse | Include the arguments left over by subcommands. |
|
nodiscard |
Returns how many arguments matched nothing, excluding the -- separator.
| recurse | Include the arguments left over by subcommands. |
| auto cli::app_t::remove_excludes | ( | app_t * | app | ) | -> bool |
Drops a subcommand exclusion.
| app | The subcommand to stop excluding. |
| auto cli::app_t::remove_excludes | ( | option_t * | opt | ) | -> bool |
Drops an option exclusion.
| opt | The option to stop excluding. |
| auto cli::app_t::remove_needs | ( | app_t * | app | ) | -> bool |
Drops a subcommand requirement.
| app | The subcommand to stop requiring. |
| auto cli::app_t::remove_needs | ( | option_t * | opt | ) | -> bool |
Drops an option requirement.
| opt | The option to stop requiring. |
| auto cli::app_t::remove_option | ( | option_t * | opt | ) | -> bool |
Removes an option from this application.
| opt | The option to remove. |
| auto cli::app_t::remove_subcommand | ( | app_t * | subcom | ) | -> bool |
Removes a subcommand from this application.
| subcom | The subcommand to remove. |
|
inline |
Requires at least one option to be used.
|
inline |
Requires a given number of options.
A negative value sets a maximum instead of an exact count; 0 means unlimited. Does not affect a help request.
| value | The count, or its negation for a maximum. |
|
inline |
Requires a number of options within a range.
A maximum of 0 means unlimited.
| min | The smallest acceptable count. |
| max | The largest acceptable count. |
|
inline |
Requires at least one subcommand to be used.
|
inline |
Requires a given number of subcommands.
A negative value sets a maximum instead of an exact count; 0 means unlimited. Does not affect a help request. The maximum is inheritable.
| value | The count, or its negation for a maximum. |
|
inline |
Requires a number of subcommands within a range.
A maximum of 0 means unlimited. The maximum is inheritable.
| min | The smallest acceptable count. |
| max | The largest acceptable count. |
|
inline |
Requires this subcommand to be used.
| require | Whether the subcommand is required. |
|
protected |
Runs this application's callback, and its subcommands', bottom up.
| final_mode | Run the final callbacks rather than the parse-complete ones. |
| suppress_final_callback | Skip this application's own final callback. |
| auto cli::app_t::set_config | ( | std::string | option_name = "", |
| std::string | default_filename = "", | ||
| const std::string & | help_message = "Read an ini file", | ||
| bool | config_required = false ) -> option_t * |
Sets the option that names a configuration file.
An empty option_name removes it.
| option_name | The name specification. |
| default_filename | The file read when the option is not given. |
| help_message | The description shown in help output. |
| config_required | Whether the file must exist. |
| auto cli::app_t::set_help_all_flag | ( | std::string | help_name = "", |
| const std::string & | help_description = "" ) -> option_t * |
Replaces the expanded-help flag.
An empty help_name removes it entirely.
| help_name | The name specification. |
| help_description | The description shown in help output. |
| auto cli::app_t::set_help_flag | ( | std::string | flag_name = "", |
| const std::string & | help_description = "" ) -> option_t * |
Replaces the help flag.
An empty flag_name removes the help flag entirely.
| flag_name | The name specification. |
| help_description | The description shown in help output. |
| auto cli::app_t::set_version_flag | ( | std::string | flag_name, |
| std::function< std::string()> | vfunc, | ||
| const std::string & | version_help = "Display program version information and exit" ) -> option_t * |
Replaces the version flag with one that generates its text.
| flag_name | The name specification. |
| vfunc | Produces the version text. |
| version_help | The description shown in help output. |
| auto cli::app_t::set_version_flag | ( | std::string | flag_name = "", |
| const std::string & | version_string = "", | ||
| const std::string & | version_help = "Display program version information and exit" ) -> option_t * |
Replaces the version flag with a fixed version string.
| flag_name | The name specification. |
| version_string | The version text to print. |
| version_help | The description shown in help output. |
|
inline |
Hides this subcommand from the processed subcommand list.
| silence | Whether to hide it. |
|
inline |
Lets a parent's subcommands be recognised from within this one.
| value | Whether to allow subcommand fallthrough. |
|
inline |
Sets a callable producing the usage line.
| usage_function | Produces the usage line. |
|
inline |
Sets the usage line shown after the description.
| usage_string | The usage line. |
|
inline |
Validates optional vector arguments before assigning them.
| validate | Whether to validate first. |
|
inline |
Validates positionals before assigning them.
| validate | Whether to validate first. |
|
nodiscard |
Renders the version string.
|
protected |
Whether /opt is accepted as an option form.
Defaults to enabled on Windows only. Inheritable.
Renders an error into the message printed by exit. Inheritable.
|
protected |
Whether options may fall through to a parent command.
Lets a parent collect options written after a subcommand name. Inheritable.
|
protected |
Largest number of subcommands accepted; 0 is unlimited. Inheritable.
Parsing stops once this many have been seen.
|
protected |
Whether this subcommand is hidden from the subcommand list.
Useful for a subcommand that only modifies how the parent behaves.