Loading...
Searching...
No Matches
CLI::Option Class Reference

`#include <Option.hpp>`

Inheritance diagram for CLI::Option:

## Public Member Functions

Basic
| Option (const Option &)=delete
Option & | operator= (const Option &)=delete
CLI11_NODISCARD std::size_t | count () const
| Count the total number of times an option was passed.
CLI11_NODISCARD bool | empty () const
| True if the option was not passed.
| operator bool () const
| This bool operator returns true if any arguments were passed or the option callback is forced.
void | clear ()
| Clear the parsed results (mostly for testing).
Setting options
Option * | expected (int value)
| Set the number of expected arguments.
Option * | expected (int value_min, int value_max)
| Set the range of expected arguments.
Option * | allow_extra_args (bool value=true)
CLI11_NODISCARD bool | get_allow_extra_args () const
| Get the current value of allow extra args.
Option * | trigger_on_parse (bool value=true)
| Set the value of trigger_on_parse which specifies that the option callback should be triggered on every parse.
CLI11_NODISCARD bool | get_trigger_on_parse () const
| The status of trigger on parse.
Option * | force_callback (bool value=true)
| Set the value of force_callback.
CLI11_NODISCARD bool | get_force_callback () const
| The status of force_callback.
Option * | run_callback_for_default (bool value=true)
CLI11_NODISCARD bool | get_run_callback_for_default () const
| Get the current value of run_callback_for_default.
Option * | callback_priority (CallbackPriority value=CallbackPriority::Normal)
Option * | check (Validator_p validator)
| Adds a shared validator.
Option * | check (Validator validator, const std::string &validator_name="")
| Adds a Validator with a built in type name.
Option * | check (std::function< std::string(const std::string &)> validator_func, std::string validator_description="", std::string validator_name="")
| Adds a Validator. Takes a const string& and returns an error message (empty if conversion/check is okay).
Option * | transform (Validator_p validator)
| Adds a shared Validator.
Option * | transform (Validator validator, const std::string &transform_name="")
| Adds a transforming Validator with a built in type name.
Option * | transform (const std::function< std::string(std::string)> &transform_func, std::string transform_description="", std::string transform_name="")
| Adds a Validator-like function that can change result.
Option * | each (const std::function< void(std::string)> &func)
| Adds a user supplied function to run on each item passed in (communicate though lambda capture).
Validator * | get_validator (const std::string &validator_name="")
| Get a named Validator.
Validator * | get_validator (int index)
| Get a Validator by index NOTE: this may not be the order of definition.
Option * | needs (Option *opt)
| Sets required options.
template<typename T = App>
Option * | needs (std::string opt_name)
| Can find a string if needed.
template<typename A, typename B, typename... ARG>
Option * | needs (A opt, B opt1, ARG... args)
| Any number supported, any mix of string and Opt.
bool | remove_needs (Option *opt)
| Remove needs link from an option. Returns true if the option really was in the needs list.
Option * | excludes (Option *opt)
| Sets excluded options.
template<typename T = App>
Option * | excludes (std::string opt_name)
| Can find a string if needed.
template<typename A, typename B, typename... ARG>
Option * | excludes (A opt, B opt1, ARG... args)
| Any number supported, any mix of string and Opt.
bool | remove_excludes (Option *opt)
| Remove needs link from an option. Returns true if the option really was in the needs list.
Option * | envname (std::string name)
| Sets environment variable to read if no option given.
template<typename T = App>
Option * | ignore_case (bool value=true)
template<typename T = App>
Option * | ignore_underscore (bool value=true)
Option * | multi_option_policy (MultiOptionPolicy value=MultiOptionPolicy::Throw)
| Take the last argument if given multiple times (or another policy).
Option * | disable_flag_override (bool value=true)
| Disable flag overrides values, e.g. –flag=is not allowed.
Accessors
CLI11_NODISCARD int | get_type_size () const
| The number of arguments the option expects.
CLI11_NODISCARD int | get_type_size_min () const
| The minimum number of arguments the option expects.
CLI11_NODISCARD int | get_type_size_max () const
| The maximum number of arguments the option expects.
CLI11_NODISCARD bool | get_inject_separator () const
| Return the inject_separator flag.
CLI11_NODISCARD std::string | get_envname () const
| The environment variable associated to this value.
CLI11_NODISCARD std::set< Option * > | get_needs () const
| The set of options needed.
CLI11_NODISCARD std::set< Option * > | get_excludes () const
| The set of options excluded.
CLI11_NODISCARD std::string | get_default_str () const
| The default value (for help printing).
CLI11_NODISCARD callback_t | get_callback () const
| Get the callback function.
CLI11_NODISCARD const std::vector< std::string > & | get_lnames () const
| Get the long names.
CLI11_NODISCARD const std::vector< std::string > & | get_snames () const
| Get the short names.
CLI11_NODISCARD const std::vector< std::string > & | get_fnames () const
| Get the flag names with specified default values.
CLI11_NODISCARD const std::string & | get_single_name () const
| Get a single name for the option, first of lname, sname, pname, envname.
CLI11_NODISCARD int | get_expected () const
| The number of times the option expects to be included.
CLI11_NODISCARD int | get_expected_min () const
| The number of times the option expects to be included.
CLI11_NODISCARD int | get_expected_max () const
| The max number of times the option expects to be included.
CLI11_NODISCARD int | get_items_expected_min () const
| The total min number of expected string values to be used.
CLI11_NODISCARD int | get_items_expected_max () const
| Get the maximum number of items expected to be returned and used for the callback.
CLI11_NODISCARD int | get_items_expected () const
| The total min number of expected string values to be used.
CLI11_NODISCARD bool | get_positional () const
| True if the argument can be given directly.
CLI11_NODISCARD bool | nonpositional () const
| True if option has at least one non-positional name.
CLI11_NODISCARD bool | has_description () const
| True if option has description.
CLI11_NODISCARD const std::string & | get_description () const
| Get the description.
Option * | description (std::string option_description)
| Set the description.
Option * | option_text (std::string text)
CLI11_NODISCARD const std::string & | get_option_text () const
Help tools
CLI11_NODISCARD 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. If all_options is false, pick just the most descriptive name to show. Use get_name(true) to get the positional name (replaces get_pname).
Parser tools
void | run_callback ()
| Process the callback.
CLI11_NODISCARD const std::string & | matching_name (const Option &other) const
| If options share any of the same names, find it.
bool | operator== (const Option &other) const
| If options share any of the same names, they are equal (not counting positional).
CLI11_NODISCARD bool | check_name (const std::string &name) const
| Check a name. Requires "-" or "--" for short / long, supports positional name.
CLI11_NODISCARD bool | check_sname (std::string name) const
| Requires "-" to be removed from string.
CLI11_NODISCARD bool | check_lname (std::string name) const
| Requires "--" to be removed from string.
CLI11_NODISCARD bool | check_fname (std::string name) const
| Requires "--" to be removed from string.
CLI11_NODISCARD std::string | get_flag_value (const std::string &name, std::string input_value) const
Option * | add_result (std::string s)
| Puts a result at the end.
Option * | add_result (std::string s, int &results_added)
| Puts a result at the end and get a count of the number of arguments actually added.
Option * | add_result (std::vector< std::string > s)
| Puts a result at the end.
CLI11_NODISCARD const results_t & | results () const
| Get the current complete results set.
CLI11_NODISCARD results_t | reduced_results () const
| Get a copy of the results.
template<typename T>
void | results (T &output) const
| Get the results as a specified type.
template<typename T>
CLI11_NODISCARD T | as () const
| Return the results as the specified type.
CLI11_NODISCARD bool | get_callback_run () const
| See if the callback has been run already.
Public Member Functions inherited from CLI::OptionBase< Option >
Option * | group (const std::string &name)
| Changes the group membership.
Option * | required (bool value=true)
| Set the option as required.
Option * | mandatory (bool value=true)
| Support Plumbum term.
Option * | always_capture_default (bool value=true)
CLI11_NODISCARD const std::string & | get_group () const
| Get the group of this option.
CLI11_NODISCARD bool | get_required () const
| True if this is a required option.
CLI11_NODISCARD bool | get_ignore_case () const
| The status of ignore case.
CLI11_NODISCARD bool | get_ignore_underscore () const
| The status of ignore_underscore.
CLI11_NODISCARD bool | get_configurable () const
| The status of configurable.
CLI11_NODISCARD bool | get_disable_flag_override () const
| The status of configurable.
CLI11_NODISCARD char | get_delimiter () const
| Get the current delimiter char.
CLI11_NODISCARD bool | get_always_capture_default () const
| Return true if this will automatically capture the default value for help printing.
CLI11_NODISCARD MultiOptionPolicy | get_multi_option_policy () const
| The status of the multi option policy.
CLI11_NODISCARD CallbackPriority | get_callback_priority () const
| The priority of callback.
Option * | take_last ()
| Set the multi option policy to take last.
Option * | take_first ()
| Set the multi option policy to take last.
Option * | take_all ()
| Set the multi option policy to take all arguments.
Option * | join ()
| Set the multi option policy to join.
Option * | configurable (bool value=true)
| Allow in a configuration file.
Option * | delimiter (char value='\0')
| Allow in a configuration file.

## Protected Attributes

Names
std::vector< std::string > | snames_ {}
| A list of the short names (-a) without the leading dashes.
std::vector< std::string > | lnames_ {}
| A list of the long names (--long) without the leading dashes.
std::vector< std::pair< std::string, std::string > > | default_flag_values_ {}
std::vector< std::string > | fnames_ {}
| a list of flag names with specified default values;
std::string | pname_ {}
| A positional name.
std::string | envname_ {}
| If given, check the environment for this option.
Help
std::string | description_ {}
| The description for help strings.
std::string | default_str_ {}
| A human readable default value, either manually set, captured, or captured by default.
std::string | option_text_ {}
| If given, replace the text that describes the option type and usage in the help text.
std::function< std::string()> | type_name_ {[]() { return std::string(); }}
std::function< std::string()> | default_function_ {}
| Run this function to capture a default (ignore if empty).
Configuration
int | type_size_max_ {1}
int | type_size_min_ {1}
| The minimum number of arguments an option should be expecting.
int | expected_min_ {1}
| The minimum number of expected values.
int | expected_max_ {1}
| The maximum number of expected values.
std::vector< Validator_p > | validators_ {}
| A list of Validators to run on each value parsed.
std::set< Option * > | needs_ {}
| A list of options that are required with this option.
std::set< Option * > | excludes_ {}
| A list of options that are excluded with this option.
Other
App * | parent_ {nullptr}
| link back up to the parent App for fallthrough
callback_t | callback_ {}
| Options store a callback to do all the work.
Protected Attributes inherited from CLI::OptionBase< Option >
std::string | group_
| The group membership.
bool | required_
| True if this is a required option.
bool | ignore_case_
| Ignore the case when matching (option, not value).
bool | ignore_underscore_
| Ignore underscores when matching (option, not value).
bool | configurable_
| Allow this option to be given in a configuration file.
bool | disable_flag_override_
| Disable overriding flag values with '=value'.
char | delimiter_
| Specify a delimiter character for vector arguments.
bool | always_capture_default_
| Automatically capture default value.
MultiOptionPolicy | multi_option_policy_
| Policy for handling multiple arguments beyond the expected Max.
CallbackPriority | callback_priority_
| Priority of callback.

## Parsing results

enum class | option_state : char { parsing = 0 , validated = 2 , reduced = 4 , callback_run = 6 }
| enumeration for the option state machine More...
results_t | results_ {}
| complete Results of parsing
results_t | proc_results_ {}
| results after reduction
option_state | current_option_state_ {option_state::parsing}
| Whether the callback has run (needed for INI parsing).
bool | allow_extra_args_ {false}
| Specify that extra args beyond type_size_max should be allowed.
bool | flag_like_ {false}
| Specify that the option should act like a flag vs regular option.
bool | run_callback_for_default_ {false}
| Control option to run the callback to set the default.
bool | inject_separator_ {false}
| flag indicating a separator needs to be injected after each argument call
bool | trigger_on_result_ {false}
| flag indicating that the option should trigger the validation and callback chain on each result when loaded
bool | force_callback_ {false}
| flag indicating that the option should force the callback regardless if any results present
| Option (std::string option_name, std::string option_description, callback_t callback, App *parent, bool allow_non_standard=false)
| Making an option by hand is not defined, it must be made by the App class.

## Custom options

Option * | type_name_fn (std::function< std::string()> typefun)
| Set the type function to run when displayed on this option.
Option * | type_name (std::string typeval)
| Set a custom option typestring.
Option * | type_size (int option_type_size)
| Set a custom option size.
Option * | type_size (int option_type_size_min, int option_type_size_max)
| Set a custom option type size range.
void | inject_separator (bool value=true)
| Set the value of the separator injection flag.
Option * | default_function (const std::function< std::string()> &func)
| Set a capture function for the default. Mostly used by App.
Option * | capture_default_str ()
| Capture the default value from the original value (if it can be captured).
Option * | default_str (std::string val)
| Set the default value string representation (does not change the contained value).
template<typename X>
Option * | default_val (const X &val)
CLI11_NODISCARD std::string | get_type_name () const
| Get the full typename for this option.

## Additional Inherited Members

Protected Member Functions inherited from CLI::OptionBase< Option >
void | copy_to (T *other) const
| Copy the contents to another similar class (one based on OptionBase).

## Member Enumeration Documentation

## option_state

enum class CLI::Option::option_state : char

strong protected

enumeration for the option state machine

Enumerator
parsing | The option is currently collecting parsed results.
validated | the results have been validated
reduced | a subset of results has been generated
callback_run | the callback has been executed

## Constructor & Destructor Documentation

## Option() [1/2]

CLI::Option::Option | ( | std::string | option_name,
|  | std::string | option_description,
|  | callback_t | callback,
|  | App * | parent,
|  | bool | allow_non_standard = false )

inline protected

Making an option by hand is not defined, it must be made by the App class.

## Option() [2/2]

CLI::Option::Option | ( | const Option & |  | ) |

delete

## Member Function Documentation

## add_result() [1/3]

Option * CLI::Option::add_result | ( | std::string | s | ) |

Puts a result at the end.

## add_result() [2/3]

Option * CLI::Option::add_result | ( | std::string | s,
|  | int & | results_added )

Puts a result at the end and get a count of the number of arguments actually added.

## add_result() [3/3]

Option * CLI::Option::add_result | ( | std::vector< std::string > | s | ) |

Puts a result at the end.

## allow_extra_args()

Option * CLI::Option::allow_extra_args | ( | bool | value = true | ) |

inline

Set the value of allow_extra_args which allows extra value arguments on the flag or option to be included with each instance

## as()

template<typename T>

CLI11_NODISCARD T CLI::Option::as | ( |  | ) | const

inline

Return the results as the specified type.

## callback_priority()

Option * CLI::Option::callback_priority | ( | CallbackPriority | value = CallbackPriority::Normal | ) |

inline

Set the value of callback priority which controls when the callback function should be called relative to other parsing operations the default This is controlled automatically but could be manipulated by the user.

## capture_default_str()

Option * CLI::Option::capture_default_str | ( |  | ) |

inline

Capture the default value from the original value (if it can be captured).

## check() [1/3]

Option * CLI::Option::check | ( | std::function< std::string(const std::string &)> | validator_func,
|  | std::string | validator_description = "",
|  | std::string | validator_name = "" )

Adds a Validator. Takes a const string& and returns an error message (empty if conversion/check is okay).

## check() [2/3]

Option * CLI::Option::check | ( | Validator | validator,
|  | const std::string & | validator_name = "" )

Adds a Validator with a built in type name.

## check() [3/3]

Option * CLI::Option::check | ( | Validator_p | validator | ) |

Adds a shared validator.

## check_fname()

CLI11_NODISCARD bool CLI::Option::check_fname | ( | std::string | name | ) | const

inline

Requires "--" to be removed from string.

## check_lname()

CLI11_NODISCARD bool CLI::Option::check_lname | ( | std::string | name | ) | const

inline

Requires "--" to be removed from string.

## check_name()

CLI11_NODISCARD bool CLI::Option::check_name | ( | const std::string & | name | ) | const

Check a name. Requires "-" or "--" for short / long, supports positional name.

## check_sname()

CLI11_NODISCARD bool CLI::Option::check_sname | ( | std::string | name | ) | const

inline

Requires "-" to be removed from string.

## clear()

void CLI::Option::clear | ( |  | ) |

inline

Clear the parsed results (mostly for testing).

## count()

CLI11_NODISCARD std::size_t CLI::Option::count | ( |  | ) | const

inline

Count the total number of times an option was passed.

## default_function()

Option * CLI::Option::default_function | ( | const std::function< std::string()> & | func | ) |

inline

Set a capture function for the default. Mostly used by App.

## default_str()

Option * CLI::Option::default_str | ( | std::string | val | ) |

inline

Set the default value string representation (does not change the contained value).

## default_val()

template<typename X>

Option * CLI::Option::default_val | ( | const X & | val | ) |

inline

Set the default value and validate the results and run the callback if appropriate to set the value into the bound value only available for types that can be converted to a string

## description()

Option * CLI::Option::description | ( | std::string | option_description | ) |

inline

Set the description.

## disable_flag_override()

Option * CLI::Option::disable_flag_override | ( | bool | value = true | ) |

inline

Disable flag overrides values, e.g. –flag=is not allowed.

## each()

Option * CLI::Option::each | ( | const std::function< void(std::string)> & | func | ) |

Adds a user supplied function to run on each item passed in (communicate though lambda capture).

## empty()

CLI11_NODISCARD bool CLI::Option::empty | ( |  | ) | const

inline

True if the option was not passed.

## envname()

Option * CLI::Option::envname | ( | std::string | name | ) |

inline

Sets environment variable to read if no option given.

## excludes() [1/3]

template<typename A, typename B, typename... ARG>

Option * CLI::Option::excludes | ( | A | opt,
|  | B | opt1,
|  | ARG... | args )

inline

Any number supported, any mix of string and Opt.

## excludes() [2/3]

Option * CLI::Option::excludes | ( | Option * | opt | ) |

Sets excluded options.

## excludes() [3/3]

template<typename T = App>

Option * CLI::Option::excludes | ( | std::string | opt_name | ) |

inline

Can find a string if needed.

## expected() [1/2]

Option * CLI::Option::expected | ( | int | value | ) |

Set the number of expected arguments.

## expected() [2/2]

Option * CLI::Option::expected | ( | int | value_min,
|  | int | value_max )

Set the range of expected arguments.

## force_callback()

Option * CLI::Option::force_callback | ( | bool | value = true | ) |

inline

Set the value of force_callback.

## get_allow_extra_args()

CLI11_NODISCARD bool CLI::Option::get_allow_extra_args | ( |  | ) | const

inline

Get the current value of allow extra args.

## get_callback()

CLI11_NODISCARD callback_t CLI::Option::get_callback | ( |  | ) | const

inline

Get the callback function.

## get_callback_run()

CLI11_NODISCARD bool CLI::Option::get_callback_run | ( |  | ) | const

inline

See if the callback has been run already.

## get_default_str()

CLI11_NODISCARD std::string CLI::Option::get_default_str | ( |  | ) | const

inline

The default value (for help printing).

## get_description()

CLI11_NODISCARD const std::string & CLI::Option::get_description | ( |  | ) | const

inline

Get the description.

## get_envname()

CLI11_NODISCARD std::string CLI::Option::get_envname | ( |  | ) | const

inline

The environment variable associated to this value.

## get_excludes()

CLI11_NODISCARD std::set< Option * > CLI::Option::get_excludes | ( |  | ) | const

inline

The set of options excluded.

## get_expected()

CLI11_NODISCARD int CLI::Option::get_expected | ( |  | ) | const

inline

The number of times the option expects to be included.

## get_expected_max()

CLI11_NODISCARD int CLI::Option::get_expected_max | ( |  | ) | const

inline

The max number of times the option expects to be included.

## get_expected_min()

CLI11_NODISCARD int CLI::Option::get_expected_min | ( |  | ) | const

inline

The number of times the option expects to be included.

## get_flag_value()

CLI11_NODISCARD std::string CLI::Option::get_flag_value | ( | const std::string & | name,
|  | std::string | input_value ) const

Get the value that goes for a flag, nominally gets the default value but allows for overrides if not disabled

## get_fnames()

CLI11_NODISCARD const std::vector< std::string > & CLI::Option::get_fnames | ( |  | ) | const

inline

Get the flag names with specified default values.

## get_force_callback()

CLI11_NODISCARD bool CLI::Option::get_force_callback | ( |  | ) | const

inline

The status of force_callback.

## get_inject_separator()

CLI11_NODISCARD bool CLI::Option::get_inject_separator | ( |  | ) | const

inline

Return the inject_separator flag.

## get_items_expected()

CLI11_NODISCARD int CLI::Option::get_items_expected | ( |  | ) | const

inline

The total min number of expected string values to be used.

## get_items_expected_max()

CLI11_NODISCARD int CLI::Option::get_items_expected_max | ( |  | ) | const

inline

Get the maximum number of items expected to be returned and used for the callback.

## get_items_expected_min()

CLI11_NODISCARD int CLI::Option::get_items_expected_min | ( |  | ) | const

inline

The total min number of expected string values to be used.

## get_lnames()

CLI11_NODISCARD const std::vector< std::string > & CLI::Option::get_lnames | ( |  | ) | const

inline

Get the long names.

## get_name()

CLI11_NODISCARD std::string CLI::Option::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. If all_options is false, pick just the most descriptive name to show. Use get_name(true) to get the positional name (replaces get_pname).

Parameters

  positional | Show the positional name
  all_options | Show every option

## get_needs()

CLI11_NODISCARD std::set< Option * > CLI::Option::get_needs | ( |  | ) | const

inline

The set of options needed.

## get_option_text()

CLI11_NODISCARD const std::string & CLI::Option::get_option_text | ( |  | ) | const

inline

## get_positional()

CLI11_NODISCARD bool CLI::Option::get_positional | ( |  | ) | const

inline

True if the argument can be given directly.

## get_run_callback_for_default()

CLI11_NODISCARD bool CLI::Option::get_run_callback_for_default | ( |  | ) | const

inline

Get the current value of run_callback_for_default.

## get_single_name()

CLI11_NODISCARD const std::string & CLI::Option::get_single_name | ( |  | ) | const

inline

Get a single name for the option, first of lname, sname, pname, envname.

## get_snames()

CLI11_NODISCARD const std::vector< std::string > & CLI::Option::get_snames | ( |  | ) | const

inline

Get the short names.

## get_trigger_on_parse()

CLI11_NODISCARD bool CLI::Option::get_trigger_on_parse | ( |  | ) | const

inline

The status of trigger on parse.

## get_type_name()

CLI11_NODISCARD std::string CLI::Option::get_type_name | ( |  | ) | const

Get the full typename for this option.

## get_type_size()

CLI11_NODISCARD int CLI::Option::get_type_size | ( |  | ) | const

inline

The number of arguments the option expects.

## get_type_size_max()

CLI11_NODISCARD int CLI::Option::get_type_size_max | ( |  | ) | const

inline

The maximum number of arguments the option expects.

## get_type_size_min()

CLI11_NODISCARD int CLI::Option::get_type_size_min | ( |  | ) | const

inline

The minimum number of arguments the option expects.

## get_validator() [1/2]

Validator * CLI::Option::get_validator | ( | const std::string & | validator_name = "" | ) |

Get a named Validator.

## get_validator() [2/2]

Validator * CLI::Option::get_validator | ( | int | index | ) |

Get a Validator by index NOTE: this may not be the order of definition.

## has_description()

CLI11_NODISCARD bool CLI::Option::has_description | ( |  | ) | const

inline

True if option has description.

## ignore_case()

template<typename T = App>

Option * CLI::Option::ignore_case | ( | bool | value = true | ) |

Ignore case

The template hides the fact that we don't have the definition of App yet. You are never expected to add an argument to the template here.

## ignore_underscore()

template<typename T = App>

Option * CLI::Option::ignore_underscore | ( | bool | value = true | ) |

Ignore underscores in the option names

The template hides the fact that we don't have the definition of App yet. You are never expected to add an argument to the template here.

## inject_separator()

void CLI::Option::inject_separator | ( | bool | value = true | ) |

inline

Set the value of the separator injection flag.

## matching_name()

CLI11_NODISCARD const std::string & CLI::Option::matching_name | ( | const Option & | other | ) | const

If options share any of the same names, find it.

## multi_option_policy()

Option * CLI::Option::multi_option_policy | ( | MultiOptionPolicy | value = MultiOptionPolicy::Throw | ) |

Take the last argument if given multiple times (or another policy).

## needs() [1/3]

template<typename A, typename B, typename... ARG>

Option * CLI::Option::needs | ( | A | opt,
|  | B | opt1,
|  | ARG... | args )

inline

Any number supported, any mix of string and Opt.

## needs() [2/3]

Option * CLI::Option::needs | ( | Option * | opt | ) |

inline

Sets required options.

## needs() [3/3]

template<typename T = App>

Option * CLI::Option::needs | ( | std::string | opt_name | ) |

inline

Can find a string if needed.

## nonpositional()

CLI11_NODISCARD bool CLI::Option::nonpositional | ( |  | ) | const

inline

True if option has at least one non-positional name.

## operator bool()

CLI::Option::operator bool | ( |  | ) | const

inline explicit

This bool operator returns true if any arguments were passed or the option callback is forced.

## operator=()

Option & CLI::Option::operator= | ( | const Option & |  | ) |

delete

## operator==()

bool CLI::Option::operator== | ( | const Option & | other | ) | const

inline

If options share any of the same names, they are equal (not counting positional).

## option_text()

Option * CLI::Option::option_text | ( | std::string | text | ) |

inline

## reduced_results()

CLI11_NODISCARD results_t CLI::Option::reduced_results | ( |  | ) | const

Get a copy of the results.

## remove_excludes()

bool CLI::Option::remove_excludes | ( | Option * | opt | ) |

Remove needs link from an option. Returns true if the option really was in the needs list.

## remove_needs()

bool CLI::Option::remove_needs | ( | Option * | opt | ) |

Remove needs link from an option. Returns true if the option really was in the needs list.

## results() [1/2]

CLI11_NODISCARD const results_t & CLI::Option::results | ( |  | ) | const

inline

Get the current complete results set.

## results() [2/2]

template<typename T>

void CLI::Option::results | ( | T & | output | ) | const

inline

Get the results as a specified type.

## run_callback()

void CLI::Option::run_callback | ( |  | ) |

Process the callback.

## run_callback_for_default()

Option * CLI::Option::run_callback_for_default | ( | bool | value = true | ) |

inline

Set the value of run_callback_for_default which controls whether the callback function should be called to set the default This is controlled automatically but could be manipulated by the user.

## transform() [1/3]

Option * CLI::Option::transform | ( | const std::function< std::string(std::string)> & | transform_func,
|  | std::string | transform_description = "",
|  | std::string | transform_name = "" )

Adds a Validator-like function that can change result.

## transform() [2/3]

Option * CLI::Option::transform | ( | Validator | validator,
|  | const std::string & | transform_name = "" )

Adds a transforming Validator with a built in type name.

## transform() [3/3]

Option * CLI::Option::transform | ( | Validator_p | validator | ) |

Adds a shared Validator.

## trigger_on_parse()

Option * CLI::Option::trigger_on_parse | ( | bool | value = true | ) |

inline

Set the value of trigger_on_parse which specifies that the option callback should be triggered on every parse.

## type_name()

Option * CLI::Option::type_name | ( | std::string | typeval | ) |

inline

Set a custom option typestring.

## type_name_fn()

Option * CLI::Option::type_name_fn | ( | std::function< std::string()> | typefun | ) |

inline

Set the type function to run when displayed on this option.

## type_size() [1/2]

Option * CLI::Option::type_size | ( | int | option_type_size | ) |

Set a custom option size.

## type_size() [2/2]

Option * CLI::Option::type_size | ( | int | option_type_size_min,
|  | int | option_type_size_max )

Set a custom option type size range.

## Member Data Documentation

## allow_extra_args_

bool CLI::Option::allow_extra_args_ {false}

protected

Specify that extra args beyond type_size_max should be allowed.

## callback_

callback_t CLI::Option::callback_ {}

protected

Options store a callback to do all the work.

## current_option_state_

option_state CLI::Option::current_option_state_ {option_state::parsing}

protected

Whether the callback has run (needed for INI parsing).

## default_flag_values_

std::vector<std::pair<std::string, std::string> > CLI::Option::default_flag_values_ {}

protected

A list of the flag names with the appropriate default value, the first part of the pair should be duplicates of what is in snames or lnames but will trigger a particular response on a flag

## default_function_

std::function<std::string()> CLI::Option::default_function_ {}

protected

Run this function to capture a default (ignore if empty).

## default_str_

std::string CLI::Option::default_str_ {}

protected

A human readable default value, either manually set, captured, or captured by default.

## description_

std::string CLI::Option::description_ {}

protected

The description for help strings.

## envname_

std::string CLI::Option::envname_ {}

protected

If given, check the environment for this option.

## excludes_

std::set<Option *> CLI::Option::excludes_ {}

protected

A list of options that are excluded with this option.

## expected_max_

int CLI::Option::expected_max_ {1}

protected

The maximum number of expected values.

## expected_min_

int CLI::Option::expected_min_ {1}

protected

The minimum number of expected values.

## flag_like_

bool CLI::Option::flag_like_ {false}

protected

Specify that the option should act like a flag vs regular option.

## fnames_

std::vector<std::string> CLI::Option::fnames_ {}

protected

a list of flag names with specified default values;

## force_callback_

bool CLI::Option::force_callback_ {false}

protected

flag indicating that the option should force the callback regardless if any results present

## inject_separator_

bool CLI::Option::inject_separator_ {false}

protected

flag indicating a separator needs to be injected after each argument call

## lnames_

std::vector<std::string> CLI::Option::lnames_ {}

protected

A list of the long names (--long) without the leading dashes.

## needs_

std::set<Option *> CLI::Option::needs_ {}

protected

A list of options that are required with this option.

## option_text_

std::string CLI::Option::option_text_ {}

protected

If given, replace the text that describes the option type and usage in the help text.

## parent_

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

protected

link back up to the parent App for fallthrough

## pname_

std::string CLI::Option::pname_ {}

protected

A positional name.

## proc_results_

results_t CLI::Option::proc_results_ {}

mutable protected

results after reduction

## results_

results_t CLI::Option::results_ {}

protected

complete Results of parsing

## run_callback_for_default_

bool CLI::Option::run_callback_for_default_ {false}

protected

Control option to run the callback to set the default.

## snames_

std::vector<std::string> CLI::Option::snames_ {}

protected

A list of the short names (-a) without the leading dashes.

## trigger_on_result_

bool CLI::Option::trigger_on_result_ {false}

protected

flag indicating that the option should trigger the validation and callback chain on each result when loaded

## type_name_

std::function<std::string()> CLI::Option::type_name_ {[]() { return std::string(); }}

protected

A human readable type value, set when App creates this

This is a lambda function so "types" can be dynamic, such as when a set prints its contents.

## type_size_max_

int CLI::Option::type_size_max_ {1}

protected

The number of arguments that make up one option. max is the nominal type size, min is the minimum number of strings

## type_size_min_

int CLI::Option::type_size_min_ {1}

protected

The minimum number of arguments an option should be expecting.

## validators_

std::vector<Validator_p> CLI::Option::validators_ {}

protected

A list of Validators to run on each value parsed.

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

- include/CLI/Option.hpp