CLI11
1.9.0
|
#include <Option.hpp>
Public Member Functions | |
Basic | |
Option (const Option &)=delete | |
Option & | operator= (const Option &)=delete |
std::size_t | count () const |
Count the total number of times an option was passed. More... | |
bool | empty () const |
True if the option was not passed. More... | |
operator bool () const | |
This class is true if option is passed. More... | |
void | clear () |
Clear the parsed results (mostly for testing) More... | |
Setting options | |
Option * | expected (int value) |
Set the number of expected arguments. More... | |
Option * | expected (int value_min, int value_max) |
Set the range of expected arguments. More... | |
Option * | allow_extra_args (bool value=true) |
bool | get_allow_extra_args () const |
Get the current value of allow extra args. More... | |
Option * | run_callback_for_default (bool value=true) |
bool | get_run_callback_for_default () const |
Get the current value of run_callback_for_default. More... | |
Option * | check (Validator validator, const std::string &validator_name="") |
Adds a Validator with a built in type name. More... | |
Option * | check (std::function< std::string(const std::string &)> Validator, 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). More... | |
Option * | transform (Validator Validator, const std::string &Validator_name="") |
Adds a transforming Validator with a built in type name. More... | |
Option * | transform (const std::function< std::string(std::string)> &func, std::string transform_description="", std::string transform_name="") |
Adds a Validator-like function that can change result. More... | |
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) More... | |
Validator * | get_validator (const std::string &Validator_name="") |
Get a named Validator. More... | |
Validator * | get_validator (int index) |
Get a Validator by index NOTE: this may not be the order of definition. More... | |
Option * | needs (Option *opt) |
Sets required options. More... | |
template<typename T = App> | |
Option * | needs (std::string opt_name) |
Can find a string if needed. More... | |
template<typename A , typename B , typename... ARG> | |
Option * | needs (A opt, B opt1, ARG... args) |
Any number supported, any mix of string and Opt. More... | |
bool | remove_needs (Option *opt) |
Remove needs link from an option. Returns true if the option really was in the needs list. More... | |
Option * | excludes (Option *opt) |
Sets excluded options. More... | |
template<typename T = App> | |
Option * | excludes (std::string opt_name) |
Can find a string if needed. More... | |
template<typename A , typename B , typename... ARG> | |
Option * | excludes (A opt, B opt1, ARG... args) |
Any number supported, any mix of string and Opt. More... | |
bool | remove_excludes (Option *opt) |
Remove needs link from an option. Returns true if the option really was in the needs list. More... | |
Option * | envname (std::string name) |
Sets environment variable to read if no option given. More... | |
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) More... | |
Option * | disable_flag_override (bool value=true) |
Disable flag overrides values, e.g. –flag=is not allowed. More... | |
Accessors | |
int | get_type_size () const |
The number of arguments the option expects. More... | |
int | get_type_size_min () const |
The minimum number of arguments the option expects. More... | |
int | get_type_size_max () const |
The maximum number of arguments the option expects. More... | |
std::string | get_envname () const |
The environment variable associated to this value. More... | |
std::set< Option * > | get_needs () const |
The set of options needed. More... | |
std::set< Option * > | get_excludes () const |
The set of options excluded. More... | |
std::string | get_default_str () const |
The default value (for help printing) More... | |
callback_t | get_callback () const |
Get the callback function. More... | |
const std::vector< std::string > & | get_lnames () const |
Get the long names. More... | |
const std::vector< std::string > & | get_snames () const |
Get the short names. More... | |
const std::vector< std::string > & | get_fnames () const |
Get the flag names with specified default values. More... | |
int | get_expected () const |
The number of times the option expects to be included. More... | |
int | get_expected_min () const |
The number of times the option expects to be included. More... | |
int | get_expected_max () const |
The max number of times the option expects to be included. More... | |
int | get_items_expected_min () const |
The total min number of expected string values to be used. More... | |
int | get_items_expected_max () const |
Get the maximum number of items expected to be returned and used for the callback. More... | |
int | get_items_expected () const |
The total min number of expected string values to be used. More... | |
bool | get_positional () const |
True if the argument can be given directly. More... | |
bool | nonpositional () const |
True if option has at least one non-positional name. More... | |
bool | has_description () const |
True if option has description. More... | |
const std::string & | get_description () const |
Get the description. More... | |
Option * | description (std::string option_description) |
Set the description. More... | |
Help tools | |
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 ) More... | |
Parser tools | |
void | run_callback () |
Process the callback. More... | |
const std::string & | matching_name (const Option &other) const |
If options share any of the same names, find it. More... | |
bool | operator== (const Option &other) const |
If options share any of the same names, they are equal (not counting positional) More... | |
bool | check_name (std::string name) const |
Check a name. Requires "-" or "--" for short / long, supports positional name. More... | |
bool | check_sname (std::string name) const |
Requires "-" to be removed from string. More... | |
bool | check_lname (std::string name) const |
Requires "--" to be removed from string. More... | |
bool | check_fname (std::string name) const |
Requires "--" to be removed from string. More... | |
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. More... | |
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. More... | |
Option * | add_result (std::vector< std::string > s) |
Puts a result at the end. More... | |
results_t | results () const |
Get a copy of the results. More... | |
results_t | reduced_results () const |
Get a copy of the results. More... | |
template<typename T , enable_if_t<!std::is_const< T >::value, detail::enabler > = detail::dummy> | |
void | results (T &output) const |
Get the results as a specified type. More... | |
template<typename T > | |
T | as () const |
Return the results as the specified type. More... | |
bool | get_callback_run () const |
See if the callback has been run already. More... | |
![]() | |
Option * | group (const std::string &name) |
Changes the group membership. More... | |
Option * | required (bool value=true) |
Set the option as required. More... | |
Option * | mandatory (bool value=true) |
Support Plumbum term. More... | |
Option * | always_capture_default (bool value=true) |
const std::string & | get_group () const |
Get the group of this option. More... | |
bool | get_required () const |
True if this is a required option. More... | |
bool | get_ignore_case () const |
The status of ignore case. More... | |
bool | get_ignore_underscore () const |
The status of ignore_underscore. More... | |
bool | get_configurable () const |
The status of configurable. More... | |
bool | get_disable_flag_override () const |
The status of configurable. More... | |
char | get_delimiter () const |
Get the current delimiter char. More... | |
bool | get_always_capture_default () const |
Return true if this will automatically capture the default value for help printing. More... | |
MultiOptionPolicy | get_multi_option_policy () const |
The status of the multi option policy. More... | |
Option * | take_last () |
Set the multi option policy to take last. More... | |
Option * | take_first () |
Set the multi option policy to take last. More... | |
Option * | take_all () |
Set the multi option policy to take all arguments. More... | |
Option * | join () |
Set the multi option policy to join. More... | |
Option * | join (char delim) |
Set the multi option policy to join with a specific delimiter. More... | |
Option * | configurable (bool value=true) |
Allow in a configuration file. More... | |
Option * | delimiter (char value='\0') |
Allow in a configuration file. More... | |
Protected Member Functions | |
Option (std::string option_name, std::string option_description, callback_t callback, App *parent) | |
Making an option by hand is not defined, it must be made by the App class. More... | |
![]() | |
void | copy_to (T *other) const |
Copy the contents to another similar class (one based on OptionBase) More... | |
Protected Attributes | |
Names | |
std::vector< std::string > | snames_ {} |
A list of the short names (-a ) without the leading dashes. More... | |
std::vector< std::string > | lnames_ {} |
A list of the long names (--long ) without the leading dashes. More... | |
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; More... | |
std::string | pname_ {} |
A positional name. More... | |
std::string | envname_ {} |
If given, check the environment for this option. More... | |
Help | |
std::string | description_ {} |
The description for help strings. More... | |
std::string | default_str_ {} |
A human readable default value, either manually set, captured, or captured by default. More... | |
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) More... | |
Configuration | |
int | type_size_max_ {1} |
int | type_size_min_ {1} |
The minimum number of arguments an option should be expecting. More... | |
int | expected_min_ {1} |
The minimum number of expected values. More... | |
int | expected_max_ {1} |
The maximum number of expected values. More... | |
std::vector< Validator > | validators_ {} |
A list of Validators to run on each value parsed. More... | |
std::set< Option * > | needs_ {} |
A list of options that are required with this option. More... | |
std::set< Option * > | excludes_ {} |
A list of options that are excluded with this option. More... | |
Other | |
App * | parent_ {nullptr} |
Remember the parent app. More... | |
callback_t | callback_ {} |
Options store a callback to do all the work. More... | |
![]() | |
std::string | group_ |
The group membership. More... | |
bool | required_ |
True if this is a required option. More... | |
bool | ignore_case_ |
Ignore the case when matching (option, not value) More... | |
bool | ignore_underscore_ |
Ignore underscores when matching (option, not value) More... | |
bool | configurable_ |
Allow this option to be given in a configuration file. More... | |
bool | disable_flag_override_ |
Disable overriding flag values with '=value'. More... | |
char | delimiter_ |
Specify a delimiter character for vector arguments. More... | |
bool | always_capture_default_ |
Automatically capture default value. More... | |
MultiOptionPolicy | multi_option_policy_ |
Policy for handling multiple arguments beyond the expected Max. More... | |
Parsing results | |
enum | option_state { option_state::parsing = 0, option_state::validated = 2, option_state::reduced = 4, option_state::callback_run = 6 } |
enumeration for the option state machine More... | |
results_t | results_ {} |
complete Results of parsing More... | |
results_t | proc_results_ {} |
results after reduction More... | |
option_state | current_option_state_ {option_state::parsing} |
Whether the callback has run (needed for INI parsing) More... | |
bool | allow_extra_args_ {false} |
Specify that extra args beyond type_size_max should be allowed. More... | |
bool | flag_like_ {false} |
Specify that the option should act like a flag vs regular option. More... | |
bool | run_callback_for_default_ {false} |
Control option to run the callback to set the default. More... | |
Custom options | |
Option * | type_name_fn (std::function< std::string()> typefun) |
Set the type function to run when displayed on this option. More... | |
Option * | type_name (std::string typeval) |
Set a custom option typestring. More... | |
Option * | type_size (int option_type_size) |
Set a custom option size. More... | |
Option * | type_size (int option_type_size_min, int option_type_size_max) |
Set a custom option type size range. More... | |
Option * | default_function (const std::function< std::string()> &func) |
Set a capture function for the default. Mostly used by App. More... | |
Option * | capture_default_str () |
Capture the default value from the original value (if it can be captured) More... | |
Option * | default_str (std::string val) |
Set the default value string representation (does not change the contained value) More... | |
template<typename X > | |
Option * | default_val (const X &val) |
std::string | get_type_name () const |
Get the full typename for this option. More... | |
|
strongprotected |
|
inlineprotected |
Making an option by hand is not defined, it must be made by the App class.
|
delete |
|
inline |
Puts a result at the end.
|
inline |
Puts a result at the end and get a count of the number of arguments actually added.
|
inline |
Puts a result at the end.
|
inline |
Set the value of allow_extra_args which allows extra value arguments on the flag or option to be included with each instance
|
inline |
Return the results as the specified type.
|
inline |
Capture the default value from the original value (if it can be captured)
|
inline |
Adds a Validator. Takes a const string& and returns an error message (empty if conversion/check is okay).
Adds a Validator with a built in type name.
|
inline |
Requires "--" to be removed from string.
|
inline |
Requires "--" to be removed from string.
|
inline |
Check a name. Requires "-" or "--" for short / long, supports positional name.
|
inline |
Requires "-" to be removed from string.
|
inline |
Clear the parsed results (mostly for testing)
|
inline |
Count the total number of times an option was passed.
|
inline |
Set a capture function for the default. Mostly used by App.
|
inline |
Set the default value string representation (does not change the contained value)
|
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
|
inline |
Set the description.
|
inline |
Disable flag overrides values, e.g. –flag=is not allowed.
|
inline |
Adds a user supplied function to run on each item passed in (communicate though lambda capture)
|
inline |
True if the option was not passed.
|
inline |
Sets environment variable to read if no option given.
|
inline |
Any number supported, any mix of string and Opt.
|
inline |
Can find a string if needed.
|
inline |
Set the number of expected arguments.
|
inline |
Set the range of expected arguments.
|
inline |
Get the current value of allow extra args.
|
inline |
Get the callback function.
|
inline |
See if the callback has been run already.
|
inline |
The default value (for help printing)
|
inline |
Get the description.
|
inline |
The environment variable associated to this value.
|
inline |
The set of options excluded.
|
inline |
The number of times the option expects to be included.
|
inline |
The max number of times the option expects to be included.
|
inline |
The number of times the option expects to be included.
|
inline |
Get the value that goes for a flag, nominally gets the default value but allows for overrides if not disabled
|
inline |
Get the flag names with specified default values.
|
inline |
The total min number of expected string values to be used.
|
inline |
Get the maximum number of items expected to be returned and used for the callback.
|
inline |
The total min number of expected string values to be used.
|
inline |
Get the long names.
|
inline |
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
)
The all list will never include a positional unless asked or that's the only name.
|
inline |
The set of options needed.
|
inline |
True if the argument can be given directly.
|
inline |
Get the current value of run_callback_for_default.
|
inline |
Get the short names.
|
inline |
Get the full typename for this option.
|
inline |
The number of arguments the option expects.
|
inline |
The maximum number of arguments the option expects.
|
inline |
The minimum number of arguments the option expects.
|
inline |
Get a named Validator.
|
inline |
Get a Validator by index NOTE: this may not be the order of definition.
|
inline |
True if option has description.
|
inline |
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.
|
inline |
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.
|
inline |
If options share any of the same names, find it.
|
inline |
Take the last argument if given multiple times (or another policy)
|
inline |
Any number supported, any mix of string and Opt.
|
inline |
Can find a string if needed.
|
inline |
True if option has at least one non-positional name.
|
inlineexplicit |
This class is true if option is passed.
|
inline |
If options share any of the same names, they are equal (not counting positional)
|
inline |
Get a copy of the results.
|
inline |
Remove needs link from an option. Returns true if the option really was in the needs list.
|
inline |
Remove needs link from an option. Returns true if the option really was in the needs list.
|
inline |
Get a copy of the results.
|
inline |
Get the results as a specified type.
|
inline |
Process the callback.
|
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.
|
inline |
Adds a Validator-like function that can change result.
|
inline |
Adds a transforming Validator with a built in type name.
|
inline |
Set a custom option typestring.
|
inline |
Set the type function to run when displayed on this option.
|
inline |
Set a custom option size.
|
inline |
Set a custom option type size range.
|
protected |
Specify that extra args beyond type_size_max should be allowed.
|
protected |
Options store a callback to do all the work.
|
protected |
Whether the callback has run (needed for INI parsing)
|
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
|
protected |
Run this function to capture a default (ignore if empty)
|
protected |
A human readable default value, either manually set, captured, or captured by default.
|
protected |
The description for help strings.
|
protected |
If given, check the environment for this option.
|
protected |
A list of options that are excluded with this option.
|
protected |
The maximum number of expected values.
|
protected |
The minimum number of expected values.
|
protected |
Specify that the option should act like a flag vs regular option.
|
protected |
a list of flag names with specified default values;
|
protected |
A list of the long names (--long
) without the leading dashes.
|
protected |
A list of options that are required with this option.
|
protected |
Remember the parent app.
|
protected |
A positional name.
|
protected |
results after reduction
|
protected |
complete Results of parsing
|
protected |
Control option to run the callback to set the default.
|
protected |
A list of the short names (-a
) without the leading dashes.
|
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.
|
protected |
The number of arguments that make up one option. max is the nominal type size, min is the minimum number of strings
|
protected |
The minimum number of arguments an option should be expecting.
|
protected |
A list of Validators to run on each value parsed.