73 std::string
group_ = std::string(
"OPTIONS");
103 template <
typename T>
void copy_to(T *other)
const;
109 CRTP *
group(
const std::string &name) {
114 return static_cast<CRTP *
>(
this);
120 return static_cast<CRTP *
>(
this);
128 return static_cast<CRTP *
>(
this);
167 auto *self =
static_cast<CRTP *
>(
this);
174 auto *self =
static_cast<CRTP *
>(
this);
181 auto self =
static_cast<CRTP *
>(
this);
188 auto *self =
static_cast<CRTP *
>(
this);
195 auto self =
static_cast<CRTP *
>(
this);
196 self->delimiter_ = delim;
204 return static_cast<CRTP *
>(
this);
210 return static_cast<CRTP *
>(
this);
302 std::function<std::string()>
type_name_{[]() {
return std::string(); }};
373 std::string option_description,
376 bool allow_non_standard =
false)
460 Option *
check(std::function<std::string(
const std::string &)> validator_func,
461 std::string validator_description =
"",
462 std::string validator_name =
"");
472 std::string transform_description =
"",
473 std::string transform_name =
"");
494 auto opt =
static_cast<T *
>(
parent_)->get_option_no_throw(opt_name);
496 throw IncorrectConstruction::MissingOption(opt_name);
502 template <
typename A,
typename B,
typename... ARG>
Option *
needs(A opt, B opt1, ARG... args) {
504 return needs(opt1, args...);
515 auto opt =
static_cast<T *
>(
parent_)->get_option_no_throw(opt_name);
517 throw IncorrectConstruction::MissingOption(opt_name);
523 template <
typename A,
typename B,
typename... ARG>
Option *
excludes(A opt, B opt1, ARG... args) {
661 bool all_options =
false
718 template <
typename T>
void results(T &output)
const {
723 retval = detail::lexical_conversion<T, T>(res, output);
728 retval = detail::lexical_conversion<T, T>(
proc_results_, output);
737 _validate_results(res);
739 _reduce_results(extra, res);
741 res = std::move(extra);
751 retval = detail::lexical_conversion<T, T>(
proc_results_, output);
836 get_name(), std::string(
"given default value(\"") + val_str +
"\") produces an error : " + err.what());
852 void _validate_results(
results_t &res)
const;
860 std::string _validate(std::string &result,
int index)
const;
863 int _add_result(std::string &&result, std::vector<std::string> &res)
const;
870#include "impl/Option_inl.hpp"
#define CLI11_NODISCARD
Definition Macros.hpp:58
Creates a command line program, with very few defaults.
Definition App.hpp:98
This converter works with INI/TOML files; to write INI files use ConfigINI.
Definition ConfigFwd.hpp:85
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition Error.hpp:205
All errors derive from this one.
Definition Error.hpp:73
CRTP * mandatory(bool value=true)
Support Plumbum term.
Definition Option.hpp:124
CRTP * take_all()
Set the multi option policy to take all arguments.
Definition Option.hpp:180
CRTP * group(const std::string &name)
Changes the group membership.
Definition Option.hpp:109
CRTP * join()
Set the multi option policy to join.
Definition Option.hpp:187
bool always_capture_default_
Automatically capture default value.
Definition Option.hpp:94
MultiOptionPolicy multi_option_policy_
Policy for handling multiple arguments beyond the expected Max.
Definition Option.hpp:97
CRTP * join(char delim)
Set the multi option policy to join with a specific delimiter.
Definition Option.hpp:194
CLI11_NODISCARD CallbackPriority get_callback_priority() const
The priority of callback.
Definition Option.hpp:161
CLI11_NODISCARD bool get_always_capture_default() const
Return true if this will automatically capture the default value for help printing.
Definition Option.hpp:155
CLI11_NODISCARD char get_delimiter() const
Get the current delimiter char.
Definition Option.hpp:152
CLI11_NODISCARD bool get_required() const
True if this is a required option.
Definition Option.hpp:137
CRTP * take_first()
Set the multi option policy to take last.
Definition Option.hpp:173
CLI11_NODISCARD bool get_ignore_case() const
The status of ignore case.
Definition Option.hpp:140
bool ignore_case_
Ignore the case when matching (option, not value)
Definition Option.hpp:79
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition Option.hpp:202
CRTP * delimiter(char value='\0')
Allow in a configuration file.
Definition Option.hpp:208
CLI11_NODISCARD MultiOptionPolicy get_multi_option_policy() const
The status of the multi option policy.
Definition Option.hpp:158
CLI11_NODISCARD bool get_configurable() const
The status of configurable.
Definition Option.hpp:146
bool configurable_
Allow this option to be given in a configuration file.
Definition Option.hpp:85
CallbackPriority callback_priority_
Priority of callback.
Definition Option.hpp:100
bool disable_flag_override_
Disable overriding flag values with '=value'.
Definition Option.hpp:88
bool required_
True if this is a required option.
Definition Option.hpp:76
CRTP * take_last()
Set the multi option policy to take last.
Definition Option.hpp:166
char delimiter_
Specify a delimiter character for vector arguments.
Definition Option.hpp:91
CRTP * always_capture_default(bool value=true)
Definition Option.hpp:126
std::string group_
The group membership.
Definition Option.hpp:73
CLI11_NODISCARD bool get_ignore_underscore() const
The status of ignore_underscore.
Definition Option.hpp:143
bool ignore_underscore_
Ignore underscores when matching (option, not value)
Definition Option.hpp:82
CLI11_NODISCARD bool get_disable_flag_override() const
The status of configurable.
Definition Option.hpp:149
CLI11_NODISCARD const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:134
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
CRTP * required(bool value=true)
Set the option as required.
Definition Option.hpp:118
OptionDefaults * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times.
Definition Option.hpp:229
OptionDefaults * ignore_case(bool value=true)
Ignore the case of the option name.
Definition Option.hpp:235
OptionDefaults * ignore_underscore(bool value=true)
Ignore underscores in the option name.
Definition Option.hpp:241
OptionDefaults * callback_priority(CallbackPriority value=CallbackPriority::Normal)
Set the callback priority.
Definition Option.hpp:223
OptionDefaults * delimiter(char value='\0')
set a delimiter character to split up single arguments to treat as multiple inputs
Definition Option.hpp:253
OptionDefaults * disable_flag_override(bool value=true)
Disable overriding flag values with an '=' segment.
Definition Option.hpp:247
Definition Option.hpp:259
CLI11_NODISCARD const std::string & get_option_text() const
Definition Option.hpp:650
CLI11_NODISCARD bool get_positional() const
True if the argument can be given directly.
Definition Option.hpp:628
std::string default_str_
A human readable default value, either manually set, captured, or captured by default.
Definition Option.hpp:294
bool run_callback_for_default_
Control option to run the callback to set the default.
Definition Option.hpp:363
CLI11_NODISCARD std::string get_envname() const
The environment variable associated to this value.
Definition Option.hpp:573
Option * excludes(Option *opt)
Sets excluded options.
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition Option.hpp:779
std::function< std::string()> type_name_
Definition Option.hpp:302
option_state
enumeration for the option state machine
Definition Option.hpp:350
@ reduced
a subset of results has been generated
Definition Option.hpp:353
@ callback_run
the callback has been executed
Definition Option.hpp:354
@ validated
the results have been validated
Definition Option.hpp:352
@ parsing
The option is currently collecting parsed results.
Definition Option.hpp:351
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_state current_option_state_
Whether the callback has run (needed for INI parsing)
Definition Option.hpp:357
std::string option_text_
If given, replace the text that describes the option type and usage in the help text.
Definition Option.hpp:297
int type_size_min_
The minimum number of arguments an option should be expecting.
Definition Option.hpp:315
Option * callback_priority(CallbackPriority value=CallbackPriority::Normal)
Definition Option.hpp:448
CLI11_NODISCARD bool check_fname(std::string name) const
Requires "--" to be removed from string.
Definition Option.hpp:691
std::string pname_
A positional name.
Definition Option.hpp:281
int expected_min_
The minimum number of expected values.
Definition Option.hpp:318
Option * expected(int value_min, int value_max)
Set the range of expected arguments.
Option * ignore_case(bool value=true)
std::set< Option * > needs_
A list of options that are required with this option.
Definition Option.hpp:326
Option * default_function(const std::function< std::string()> &func)
Set a capture function for the default. Mostly used by App.
Definition Option.hpp:794
CLI11_NODISCARD int get_type_size_min() const
The minimum number of arguments the option expects.
Definition Option.hpp:565
bool remove_excludes(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
CLI11_NODISCARD bool check_sname(std::string name) const
Requires "-" to be removed from string.
Definition Option.hpp:681
bool trigger_on_result_
flag indicating that the option should trigger the validation and callback chain on each result when ...
Definition Option.hpp:367
bool flag_like_
Specify that the option should act like a flag vs regular option.
Definition Option.hpp:361
Option * add_result(std::string s)
Puts a result at the end.
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition Option.hpp:329
bool force_callback_
flag indicating that the option should force the callback regardless if any results present
Definition Option.hpp:369
CLI11_NODISCARD bool get_callback_run() const
See if the callback has been run already.
Definition Option.hpp:766
Option & operator=(const Option &)=delete
CLI11_NODISCARD bool get_force_callback() const
The status of force_callback.
Definition Option.hpp:435
Option * check(Validator_p validator)
Adds a shared validator.
std::vector< std::string > fnames_
a list of flag names with specified default values;
Definition Option.hpp:278
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.
Definition Option.hpp:372
CLI11_NODISCARD std::string get_flag_value(const std::string &name, std::string input_value) const
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)
Option * option_text(std::string text)
Definition Option.hpp:645
CLI11_NODISCARD bool get_run_callback_for_default() const
Get the current value of run_callback_for_default.
Definition Option.hpp:444
CLI11_NODISCARD std::string get_default_str() const
The default value (for help printing)
Definition Option.hpp:582
CLI11_NODISCARD bool nonpositional() const
True if option has at least one non-positional name.
Definition Option.hpp:631
CLI11_NODISCARD int get_items_expected_min() const
The total min number of expected string values to be used.
Definition Option.hpp:617
Option * expected(int value)
Set the number of expected arguments.
Option * transform(Validator validator, const std::string &transform_name="")
Adds a transforming Validator with a built in type name.
CLI11_NODISCARD std::string get_type_name() const
Get the full typename for this option.
CLI11_NODISCARD bool check_lname(std::string name) const
Requires "--" to be removed from string.
Definition Option.hpp:686
Option(const Option &)=delete
CLI11_NODISCARD const results_t & results() const
Get the current complete results set.
Definition Option.hpp:712
Option * disable_flag_override(bool value=true)
Disable flag overrides values, e.g. –flag=is not allowed.
Definition Option.hpp:553
CLI11_NODISCARD int get_items_expected_max() const
Get the maximum number of items expected to be returned and used for the callback.
Definition Option.hpp:620
std::vector< std::string > snames_
A list of the short names (-a) without the leading dashes.
Definition Option.hpp:268
results_t proc_results_
results after reduction
Definition Option.hpp:348
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:389
Option * run_callback_for_default(bool value=true)
Definition Option.hpp:439
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.
Definition Option.hpp:791
Option * allow_extra_args(bool value=true)
Definition Option.hpp:415
Option * trigger_on_parse(bool value=true)
Set the value of trigger_on_parse which specifies that the option callback should be triggered on eve...
Definition Option.hpp:422
Option * transform(Validator_p validator)
Adds a shared Validator.
CLI11_NODISCARD callback_t get_callback() const
Get the callback function.
Definition Option.hpp:585
CLI11_NODISCARD bool get_inject_separator() const
Return the inject_separator flag.
Definition Option.hpp:570
std::vector< Validator_p > validators_
A list of Validators to run on each value parsed.
Definition Option.hpp:323
Option * type_size(int option_type_size)
Set a custom option size.
CLI11_NODISCARD results_t reduced_results() const
Get a copy of the results.
App * parent_
link back up to the parent App for fallthrough
Definition Option.hpp:336
CLI11_NODISCARD bool get_trigger_on_parse() const
The status of trigger on parse.
Definition Option.hpp:427
CLI11_NODISCARD const std::vector< std::string > & get_lnames() const
Get the long names.
Definition Option.hpp:588
CLI11_NODISCARD bool check_name(const std::string &name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
int expected_max_
The maximum number of expected values.
Definition Option.hpp:320
CLI11_NODISCARD std::set< Option * > get_excludes() const
The set of options excluded.
Definition Option.hpp:579
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 ok...
Option * excludes(std::string opt_name)
Can find a string if needed.
Definition Option.hpp:514
CLI11_NODISCARD int get_items_expected() const
The total min number of expected string values to be used.
Definition Option.hpp:625
CLI11_NODISCARD std::set< Option * > get_needs() const
The set of options needed.
Definition Option.hpp:576
std::string description_
The description for help strings.
Definition Option.hpp:291
CLI11_NODISCARD const std::vector< std::string > & get_snames() const
Get the short names.
Definition Option.hpp:591
CLI11_NODISCARD int get_type_size_max() const
The maximum number of arguments the option expects.
Definition Option.hpp:567
bool inject_separator_
flag indicating a separator needs to be injected after each argument call
Definition Option.hpp:365
bool remove_needs(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
CLI11_NODISCARD const std::string & get_description() const
Get the description.
Definition Option.hpp:637
void run_callback()
Process the callback.
CLI11_NODISCARD const std::string & get_single_name() const
Get a single name for the option, first of lname, sname, pname, envname.
Definition Option.hpp:596
CLI11_NODISCARD int get_expected() const
The number of times the option expects to be included.
Definition Option.hpp:609
callback_t callback_
Options store a callback to do all the work.
Definition Option.hpp:339
CLI11_NODISCARD bool empty() const
True if the option was not passed.
Definition Option.hpp:392
CLI11_NODISCARD int get_expected_min() const
The number of times the option expects to be included.
Definition Option.hpp:612
void clear()
Clear the parsed results (mostly for testing)
Definition Option.hpp:398
CLI11_NODISCARD int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:614
Option * add_result(std::vector< std::string > s)
Puts a result at the end.
CLI11_NODISCARD const std::string & matching_name(const Option &other) const
If options share any of the same names, find it.
Option * capture_default_str()
Capture the default value from the original value (if it can be captured)
Definition Option.hpp:800
void results(T &output) const
Get the results as a specified type.
Definition Option.hpp:718
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition Option.hpp:808
CLI11_NODISCARD int get_type_size() const
The number of arguments the option expects.
Definition Option.hpp:562
std::string envname_
If given, check the environment for this option.
Definition Option.hpp:284
std::function< std::string()> default_function_
Run this function to capture a default (ignore if empty)
Definition Option.hpp:305
CLI11_NODISCARD bool get_allow_extra_args() const
Get the current value of allow extra args.
Definition Option.hpp:420
Option * ignore_underscore(bool value=true)
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition Option.hpp:275
Option * envname(std::string name)
Sets environment variable to read if no option given.
Definition Option.hpp:532
Option * type_name_fn(std::function< std::string()> typefun)
Set the type function to run when displayed on this option.
Definition Option.hpp:773
Option * default_val(const X &val)
Definition Option.hpp:815
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 * needs(Option *opt)
Sets required options.
Definition Option.hpp:485
int type_size_max_
Definition Option.hpp:313
Option * needs(A opt, B opt1, ARG... args)
Any number supported, any mix of string and Opt.
Definition Option.hpp:502
bool allow_extra_args_
Specify that extra args beyond type_size_max should be allowed.
Definition Option.hpp:359
Option * description(std::string option_description)
Set the description.
Definition Option.hpp:640
std::vector< std::string > lnames_
A list of the long names (--long) without the leading dashes.
Definition Option.hpp:271
Option * force_callback(bool value=true)
Set the value of force_callback.
Definition Option.hpp:430
Validator * get_validator(int index)
Get a Validator by index NOTE: this may not be the order of definition.
bool operator==(const Option &other) const
If options share any of the same names, they are equal (not counting positional)
Definition Option.hpp:675
Option * check(Validator validator, const std::string &validator_name="")
Adds a Validator with a built in type name.
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...
Option * needs(std::string opt_name)
Can find a string if needed.
Definition Option.hpp:493
CLI11_NODISCARD const std::vector< std::string > & get_fnames() const
Get the flag names with specified default values.
Definition Option.hpp:594
CLI11_NODISCARD bool has_description() const
True if option has description.
Definition Option.hpp:634
results_t results_
complete Results of parsing
Definition Option.hpp:346
Validator * get_validator(const std::string &validator_name="")
Get a named Validator.
CLI11_NODISCARD T as() const
Return the results as the specified type.
Definition Option.hpp:759
Option * excludes(A opt, B opt1, ARG... args)
Any number supported, any mix of string and Opt.
Definition Option.hpp:523
Some validators that are provided.
Definition Validators.hpp:54
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
Definition TypeTools.hpp:337
std::enable_if< std::is_integral< T >::value, bool >::type checked_multiply(T &a, T b)
Performs a *= b; if it doesn't cause integer overflow. Returns false otherwise.
Definition Validators.hpp:306
CLI11_INLINE std::tuple< std::vector< std::string >, std::vector< std::string >, std::string > get_names(const std::vector< std::string > &input, bool allow_non_standard=false)
Get a vector of short names, one of long names, and a single name.
constexpr int expected_max_vector_size
Definition StringTools.hpp:48
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition StringTools.hpp:167
CLI11_INLINE std::vector< std::string > split_names(std::string current)
CLI11_INLINE std::ptrdiff_t find_member(std::string name, const std::vector< std::string > names, bool ignore_case=false, bool ignore_underscore=false)
Check if a string is a member of a list of strings and optionally ignore case or ignore underscores.
std::shared_ptr< Validator > Validator_p
Definition Option.hpp:40
CallbackPriority
enumeration for the callback priority
Definition Option.hpp:54
@ First
Definition Option.hpp:56
@ PreRequirementsCheckPreHelp
Definition Option.hpp:57
@ Normal
Definition Option.hpp:60
@ NormalPreHelp
Definition Option.hpp:59
@ PreRequirementsCheck
Definition Option.hpp:58
@ Last
Definition Option.hpp:62
@ FirstPreHelp
Definition Option.hpp:55
@ LastPreHelp
Definition Option.hpp:61
@ ConversionError
Definition Error.hpp:50
@ IncorrectConstruction
Definition Error.hpp:46
MultiOptionPolicy
Enumeration of the multiOption Policy selection.
Definition Option.hpp:43
@ TakeAll
just get all the passed argument regardless
Definition Option.hpp:48
@ TakeFirst
take only the first Expected number of arguments
Definition Option.hpp:46
@ Reverse
take only the last Expected number of arguments in reverse order
Definition Option.hpp:50
@ Throw
Throw an error if any extra arguments were given.
Definition Option.hpp:44
@ TakeLast
take only the last Expected number of arguments
Definition Option.hpp:45
@ Sum
sum all the arguments together if numerical or concatenate directly without delimiter
Definition Option.hpp:49
@ Join
merge all the arguments together into a single string via the delimiter character default(' ')
Definition Option.hpp:47
std::function< bool(const results_t &)> callback_t
callback function definition
Definition Option.hpp:33
@ Normal
The normal, detailed help.
Definition FormatterFwd.hpp:33
std::vector< std::string > results_t
Definition Option.hpp:31
std::unique_ptr< Option > Option_p
Definition Option.hpp:39