38#define CLI11_PARSE(app, ...) \
40 (app).parse(__VA_ARGS__); \
41 } catch(const CLI::ParseError &e) { \
42 return (app).exit(e); \
51namespace FailureMessage {
65using App_p = std::shared_ptr<App>;
184 using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
295 std::vector<std::string> normalized_argv_{};
298 std::vector<char *> normalized_argv_view_{};
302 App(std::string app_description, std::string app_name,
App *parent);
309 explicit App(std::string app_description =
"", std::string app_name =
"")
310 :
App(app_description, app_name, nullptr) {
311 set_help_flag(
"-h,--help",
"Print this help message and exit");
482 formatter_ = std::make_shared<FormatterLambda>(fmt);
518 std::string option_description =
"",
519 bool defaulted =
false,
520 std::function<std::string()> func = {});
523 template <
typename AssignTo,
524 typename ConvertTo = AssignTo,
528 std::string option_description =
"") {
531 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
534 Option *opt =
add_option(option_name, fun, option_description,
false, [&variable]() {
542 opt->
type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
543 opt->
expected(detail::expected_count<ConvertTo>::value);
552 std::string option_description =
"") {
558 Option *opt =
add_option(option_name, fun, option_description,
false, []() {
return std::string{}; });
561 opt->
expected(detail::expected_count<AssignTo>::value);
567 template <
typename ArgType>
569 const std::function<
void(
const ArgType &)> &func,
570 std::string option_description =
"") {
581 Option *opt =
add_option(option_name, std::move(fun), option_description,
false);
584 opt->
expected(detail::expected_count<ArgType>::value);
594 template <
typename T,
609 const std::string &versionString =
"",
610 const std::string &version_help =
"Display program version information and exit");
614 std::function<std::string()> vfunc,
615 const std::string &version_help =
"Display program version information and exit");
619 Option *_add_flag_internal(std::string flag_name,
CLI::callback_t fun, std::string flag_description);
628 template <
typename T,
632 return _add_flag_internal(flag_name,
CLI::callback_t(), flag_description);
637 template <
typename T,
639 !std::is_constructible<std::function<void(
int)>, T>::value,
643 std::string flag_description =
"") {
647 return lexical_cast(res[0], flag_result);
649 auto *opt = _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
654 template <
typename T,
658 std::vector<T> &flag_results,
659 std::string flag_description =
"") {
662 for(
const auto &elem : res) {
664 flag_results.emplace_back();
665 retval &= lexical_cast(elem, flag_results.back());
669 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
676 std::function<
void(
void)> function,
677 std::string flag_description =
"");
681 std::function<
void(std::int64_t)> function,
682 std::string flag_description =
"");
687 std::function<
void(std::int64_t)> function,
688 std::string flag_description =
"") {
689 return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
695 std::string default_filename =
"",
696 const std::string &help_message =
"Read an ini file",
697 bool config_required =
false);
703 template <
typename T = Option_group>
708 auto option_group = std::make_shared<T>(std::move(group_description), group_name,
this);
709 auto *ptr = option_group.get();
711 App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
833 explicit operator bool()
const {
return parsed_ > 0; }
853 void parse(
int argc,
const char *
const *argv);
854 void parse(
int argc,
const wchar_t *
const *argv);
857 template <
class CharT>
void parse_char_t(
int argc,
const CharT *
const *argv);
864 void parse(std::string commandline,
bool program_name_included =
false);
865 void parse(std::wstring commandline,
bool program_name_included =
false);
869 void parse(std::vector<std::string> &args);
872 void parse(std::vector<std::string> &&args);
882 int exit(
const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr)
const;
975 usage_ = std::move(usage_string);
979 App *
usage(std::function<std::string()> usage_function) {
985 footer_ = std::move(footer_string);
989 App *
footer(std::function<std::string()> footer_function) {
1018#if CLI11_USE_STATIC_RTTI == 0
1035 std::vector<const Option *>
get_options(
const std::function<
bool(
const Option *)> filter = {})
const;
1049 if(opt ==
nullptr) {
1058 if(opt ==
nullptr) {
1219 void run_callback(
bool final_mode =
false,
bool suppress_final_callback =
false);
1226 bool ignore_used_subcommands =
true)
const;
1267 void _parse(std::vector<std::string> &&args);
1299 _find_subcommand(
const std::string &subc_name,
bool ignore_disabled,
bool ignore_used)
const noexcept;
1333 :
App(std::move(group_description),
"", parent) {
1357 subc->get_parent()->remove_subcommand(subcom);
1409 return app->_parse_arg(std::forward<Args>(
args)...);
1414 return app->_parse_subcommand(std::forward<Args>(
args)...);
1418 template <
typename...
Args>
1421 return app->_parse_arg(std::forward<Args>(
args)...);
1425 template <
typename...
Args>
1428 return app->_parse_subcommand(std::forward<Args>(
args)...);
1439#ifndef CLI11_COMPILE
1440#include "impl/App_inl.hpp"
#define CLI11_INLINE
Definition Macros.hpp:129
#define CLI11_NODISCARD
Definition Macros.hpp:47
Creates a command line program, with very few defaults.
Definition App.hpp:88
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
CLI11_NODISCARD char ** ensure_utf8(char **argv)
Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1065
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition App.hpp:466
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
App * _get_fallthrough_parent()
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
void _process()
Process callbacks and such.
CLI11_NODISCARD std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition App.hpp:995
App * usage(std::function< std::string()> usage_function)
Set usage.
Definition App.hpp:979
CLI11_NODISCARD bool get_enabled_by_default() const
Get the status of disabled by default.
Definition App.hpp:1135
Option * config_ptr_
Pointer to the config option.
Definition App.hpp:286
CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const
Check with name instead of pointer to see if subcommand was selected.
Definition App.hpp:910
Option * set_version_flag(std::string flag_name, std::function< std::string()> vfunc, const std::string &version_help="Display program version information and exit")
Generate the version string through a callback function.
CLI11_NODISCARD bool get_configurable() const
Check the status of the allow windows style options.
Definition App.hpp:1086
CLI11_NODISCARD std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
CLI11_NODISCARD bool check_name(std::string name_to_check) const
Check the name, case insensitive and underscore insensitive if set.
void parse(std::string commandline, bool program_name_included=false)
Option * add_option_no_stream(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition App.hpp:550
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index=0) const
Get an owning pointer to subcommand by index.
CLI11_NODISCARD std::string get_usage() const
Generate and return the usage.
Definition App.hpp:1092
CLI11_NODISCARD std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition App.hpp:1010
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition App.hpp:589
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition App.hpp:487
bool remove_excludes(App *app)
Removes a subcommand from the excludes list of this subcommand.
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition App.hpp:427
App * disabled_by_default(bool disable=true)
Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disable...
Definition App.hpp:390
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
CLI11_NODISCARD App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
CLI11_NODISCARD bool _valid_subcommand(const std::string ¤t, bool ignore_used=true) const
Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached.
Option * set_version_flag(std::string flag_name="", const std::string &versionString="", const std::string &version_help="Display program version information and exit")
Set a version flag and version display string, replace the existing one if present.
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition App.hpp:267
void _parse(std::vector< std::string > &args)
Internal parse function.
void _parse(std::vector< std::string > &&args)
Internal parse function.
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition App.hpp:384
App * clear_aliases()
clear all the aliases of the current App
Definition App.hpp:1178
CLI11_NODISCARD bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition App.hpp:1074
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition App.hpp:366
App * fallthrough(bool value=true)
Definition App.hpp:826
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition App.hpp:264
Option * get_config_ptr()
Get a pointer to the config option.
Definition App.hpp:1154
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition App.hpp:217
CLI11_NODISCARD bool get_allow_extras() const
Get the status of allow extras.
Definition App.hpp:1117
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition App.hpp:258
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition App.hpp:767
CLI11_NODISCARD std::size_t count_all() const
Option * get_option(std::string option_name)
Get an option by name (non-const version)
Definition App.hpp:1056
std::string usage_
Usage to put after program/subcommand description in the help output INHERITABLE.
Definition App.hpp:154
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition App.hpp:144
CLI11_NODISCARD const Option * get_version_ptr() const
Get a pointer to the version option. (const)
Definition App.hpp:1163
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
CLI11_NODISCARD bool get_fallthrough() const
Check the status of fallthrough.
Definition App.hpp:1077
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition App.hpp:121
CLI11_NODISCARD bool get_prefix_command() const
Get the prefix command status.
Definition App.hpp:1114
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition App.hpp:526
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1105
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app.
Definition App.hpp:118
startup_mode
Definition App.hpp:239
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1068
CLI11_NODISCARD bool get_immediate_callback() const
Get the status of disabled.
Definition App.hpp:1129
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1145
App * require_subcommand(int value)
Definition App.hpp:776
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition App.hpp:496
CLI11_NODISCARD App * get_subcommand(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
void _process_extras()
Throw an error if anything is left over and should not be.
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition App.hpp:160
config_extras_mode allow_config_extras_
Definition App.hpp:109
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition App.hpp:1097
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition App.hpp:372
Option * version_ptr_
A pointer to a version flag if there is one.
Definition App.hpp:172
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition App.hpp:1151
App * parent_
A pointer to the parent if this is a subcommand.
Definition App.hpp:273
std::set< Option * > exclude_options_
Definition App.hpp:202
App * prefix_command(bool allow=true)
Do not parse anything after the first unrecognized option and return.
Definition App.hpp:444
App * group(std::string group_name)
Changes the group membership.
Definition App.hpp:761
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
std::function< std::string()> footer_callback_
This is a function that generates a footer to put after all other options in help output.
Definition App.hpp:163
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition App.hpp:134
virtual void pre_callback()
Definition App.hpp:842
void parse(int argc, const char *const *argv)
T * add_option_group(std::string group_name, std::string group_description="")
creates an option group as part of the given app
Definition App.hpp:704
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition App.hpp:1166
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition App.hpp:623
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition App.hpp:99
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition App.hpp:195
App(std::string app_description="", std::string app_name="")
Create a new program. Pass in the same arguments as main(), along with a help string.
Definition App.hpp:309
CLI11_NODISCARD const Option * get_help_ptr() const
Get a pointer to the help flag. (const)
Definition App.hpp:1148
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition App.hpp:223
CLI::App_p get_subcommand_ptr(App *subcom) const
Check to see if a subcommand is part of this command and get a shared_ptr to it.
App * allow_windows_style_options(bool value=true)
Definition App.hpp:454
missing_t missing_
Definition App.hpp:189
CLI11_NODISCARD bool get_validate_positionals() const
Get the status of validating positionals.
Definition App.hpp:1137
Option * add_option_function(std::string option_name, const std::function< void(const ArgType &)> &func, std::string option_description="")
Add option for a callback of a specific type.
Definition App.hpp:568
CLI11_NODISCARD std::string version() const
Displays a version string.
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition App.hpp:261
void clear()
Reset the parsed data.
App * usage(std::string usage_string)
Set usage.
Definition App.hpp:974
bool remove_needs(App *app)
Removes a subcommand from the needs list of this subcommand.
void failure_message(std::function< std::string(const App *, const Error &e)> function)
Provide a function to print a help message. The function gets access to the App pointer and error.
Definition App.hpp:877
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
bool has_automatic_name_
If set to true the name was automatically generated from the command line vs a user set name.
Definition App.hpp:115
std::function< std::string(const App *, const Error &e) failure_message_)
The error message printing function INHERITABLE.
Definition App.hpp:178
void _process_config_file()
Read and process a configuration file (main app only)
CLI11_NODISCARD App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1111
App * enabled_by_default(bool enable=true)
Definition App.hpp:401
void _process_extras(std::vector< std::string > &args)
App * footer(std::string footer_string)
Set footer.
Definition App.hpp:984
App * needs(Option *opt)
Definition App.hpp:939
App * require_option(int value)
Definition App.hpp:805
std::vector< App * > get_subcommands(const std::function< bool(App *)> &filter)
virtual ~App()=default
virtual destructor
CLI11_NODISCARD std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition App.hpp:889
std::vector< Option_p > options_
The list of options, stored locally.
Definition App.hpp:147
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition App.hpp:169
bool validate_optional_arguments_
If set to true optional vector arguments are validated before assigning INHERITABLE.
Definition App.hpp:251
void parse(std::vector< std::string > &args)
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
CLI11_NODISCARD std::vector< std::string > remaining_for_passthrough(bool recurse=false) const
This returns the missing options in a form ready for processing by another command line program.
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
CLI11_NODISCARD const Option * get_option_no_throw(std::string option_name) const noexcept
Get an option by name (noexcept const version)
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition App.hpp:137
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition App.hpp:796
void parse(std::vector< std::string > &&args)
The real work is done here. Expects a reversed vector.
std::function< std::string()> usage_callback_
This is a function that generates a usage to put after program/subcommand description in help output.
Definition App.hpp:157
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition App.hpp:354
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition App.hpp:237
bool immediate_callback_
Definition App.hpp:128
App * add_subcommand(CLI::App_p subcom)
Add a previously created app as a subcommand.
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition App.hpp:1120
Option * add_flag(std::string flag_name, T &flag_description)
Definition App.hpp:631
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
void parse_from_stream(std::istream &input)
CLI11_NODISCARD bool get_ignore_case() const
Check the status of ignore_case.
Definition App.hpp:1071
App * parse_complete_callback(std::function< void()> pc_callback)
Definition App.hpp:347
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition App.hpp:245
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition App.hpp:481
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1175
App * description(std::string app_description)
Set the description of the app.
Definition App.hpp:1029
CLI11_NODISCARD std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition App.hpp:1016
Option * set_help_all_flag(std::string help_name="", const std::string &help_description="")
Set a help all flag, replaced the existing one if present.
std::string description_
Description of the current program/subcommand.
Definition App.hpp:102
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type, bool local_processing_only)
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition App.hpp:924
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
int exit(const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
Print a nice error message and return the exit code.
CLI11_NODISCARD bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition App.hpp:1083
std::vector< const App * > get_subcommands(const std::function< bool(const App *)> &filter) const
Option * get_version_ptr()
Get a pointer to the version option.
Definition App.hpp:1160
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1108
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition App.hpp:270
CLI11_NODISCARD App * get_subcommand(int index=0) const
Get a pointer to subcommand by index.
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition App.hpp:184
CLI11_NODISCARD bool get_disabled() const
Get the status of disabled.
Definition App.hpp:1123
Option * add_flag_callback(std::string flag_name, std::function< void(void)> function, std::string flag_description="")
Add option for callback that is triggered with a true flag and takes no arguments.
CLI11_NODISCARD bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition App.hpp:1080
std::vector< const Option * > get_options(const std::function< bool(const Option *)> filter={}) const
Get the list of options (user facing function, so returns raw pointers), has optional filter function...
CLI11_NODISCARD detail::Classifier _recognize(const std::string ¤t, bool ignore_used_subcommands=true) const
Selects a Classifier enum based on the type of the current argument.
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition App.hpp:279
void _parse_stream(std::istream &input)
Internal function to parse a stream.
CLI11_NODISCARD bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition App.hpp:493
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition App.hpp:198
CLI11_NODISCARD bool get_disabled_by_default() const
Get the status of disabled by default.
Definition App.hpp:1132
Option * add_flag(std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
Vector version to capture multiple flags.
Definition App.hpp:657
CLI11_NODISCARD std::size_t count() const
Definition App.hpp:754
bool ignore_case_
If true, the program name is not case sensitive INHERITABLE.
Definition App.hpp:220
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1089
Option * set_config(std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false)
Set a configuration ini file option, or clear it if no name passed.
bool silent_
Definition App.hpp:255
CLI11_NODISCARD const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version)
Definition App.hpp:1169
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition App.hpp:131
App * final_callback(std::function< void()> app_callback)
Definition App.hpp:340
std::string group_
The group membership INHERITABLE.
Definition App.hpp:276
CLI11_NODISCARD std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition App.hpp:124
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition App.hpp:415
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition App.hpp:166
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition App.hpp:989
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition App.hpp:915
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
CLI11_NODISCARD std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition App.hpp:1013
void parse(std::wstring commandline, bool program_name_included=false)
void parse(int argc, const wchar_t *const *argv)
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:893
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
App * get_subcommand(const App *subcom) const
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition App.hpp:904
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition App.hpp:1142
CLI11_NODISCARD bool _has_remaining_positionals() const
Count the required remaining positional arguments.
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition App.hpp:460
CLI11_NODISCARD std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
bool fallthrough_
Allow subcommand fallthrough, so that parent commands can collect commands after subcommand....
Definition App.hpp:226
std::set< Option * > need_options_
Definition App.hpp:210
CLI11_NODISCARD bool get_validate_optional_arguments() const
Get the status of validating optional vector arguments.
Definition App.hpp:1139
App * alias(std::string app_name)
Set an alias for the app.
CLI11_NODISCARD bool get_silent() const
Get the status of silence.
Definition App.hpp:1126
std::set< App * > need_subcommands_
Definition App.hpp:206
App * validate_optional_arguments(bool validate=true)
Set the subcommand to validate optional vector arguments before assigning.
Definition App.hpp:421
bool prefix_command_
If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
Definition App.hpp:112
void _process_callbacks()
Process callbacks. Runs on all subcommands.
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition App.hpp:475
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition App.hpp:192
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition App.hpp:597
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
CLI11_NODISCARD const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition App.hpp:1193
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition App.hpp:248
startup_mode default_startup
Definition App.hpp:242
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition App.hpp:438
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition App.hpp:641
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition App.hpp:105
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1026
App & operator=(const App &)=delete
App * require_option(std::size_t min, std::size_t max)
Definition App.hpp:818
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
std::vector< Option * > get_options(const std::function< bool(Option *)> filter={})
Non-const version of the above.
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1102
void _process_config_file(const std::string &config_file, bool throw_error)
Read and process a particular configuration file.
Option * add_flag_function(std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
CLI11_NODISCARD const Option * get_config_ptr() const
Get a pointer to the config option. (const)
Definition App.hpp:1157
bool _parse_subcommand(std::vector< std::string > &args)
void _parse_config(const std::vector< ConfigItem > &args)
CLI11_NODISCARD const std::string & _compare_subcommand_names(const App &subcom, const App &base) const
Helper function to run through all possible comparisons of subcommand names to check there is no over...
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1172
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition App.hpp:378
App * callback(std::function< void()> app_callback)
Definition App.hpp:329
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition App.hpp:175
App * needs(App *app)
Definition App.hpp:947
App * require_subcommand(std::size_t min, std::size_t max)
Definition App.hpp:789
CLI11_NODISCARD const Option * get_option(std::string option_name) const
Get an option by name.
Definition App.hpp:1047
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition App.hpp:229
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition App.hpp:289
All errors derive from this one.
Definition Error.hpp:71
CRTP * always_capture_default(bool value=true)
Definition Option.hpp:105
Definition Option.hpp:192
Extension of App to better manage groups of options.
Definition App.hpp:1330
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition App.hpp:1355
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition App.hpp:1339
Option_group(std::string group_description, std::string group_name, App *parent)
Definition App.hpp:1332
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition App.hpp:1349
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition App.hpp:1347
Definition Option.hpp:229
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition Option.hpp:722
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Option * expected(int value)
Set the number of expected arguments.
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:355
Option * run_callback_for_default(bool value=true)
Definition Option.hpp:405
Option * type_size(int option_type_size)
Set a custom option size.
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition Option.hpp:751
Option * force_callback(bool value=true)
Set the value of force_callback.
Definition Option.hpp:396
CLI11_INLINE std::string help(const App *app, const Error &e)
Printout the full help string on error (if this fn is set, the old default for CLI11)
CLI11_INLINE std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+)
constexpr enabler dummy
An instance to use in EnableIf.
Definition TypeTools.hpp:37
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition TypeTools.hpp:349
Option * default_flag_modifiers(Option *opt)
helper functions for adding in appropriate flag modifiers for add_flag
Definition App.hpp:71
Classifier
Definition App.hpp:47
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition StringTools.hpp:162
enabler
Simple empty scoped class.
Definition TypeTools.hpp:34
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition TypeTools.hpp:1015
std::shared_ptr< App > App_p
Definition App.hpp:65
ConfigBase ConfigTOML
the default Config is the TOML file format
Definition ConfigFwd.hpp:170
CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition App.hpp:61
typename std::enable_if< B, T >::type enable_if_t
Definition TypeTools.hpp:45
CLI11_INLINE void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
AppFormatMode
Definition FormatterFwd.hpp:30
@ Normal
The normal, detailed help.
@ TakeAll
just get all the passed argument regardless
@ Sum
sum all the arguments together if numerical or concatenate directly without delimiter
CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
std::function< bool(const results_t &)> callback_t
callback function definition
Definition Option.hpp:31
std::vector< std::string > results_t
Definition Option.hpp:29
Holds values to load into Options.
Definition ConfigFwd.hpp:27
This class is simply to allow tests access to App's protected functions.
Definition App.hpp:1404
static auto parse_subcommand(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_subcommand)(App, Args...)>::type
Wrap _parse_subcommand, perfectly forward arguments and return.
Definition App.hpp:1426
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition App.hpp:1432
static auto parse_arg(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_arg)(App, Args...)>::type
Wrap _parse_short, perfectly forward arguments and return.
Definition App.hpp:1419
This will only trigger for actual void type.
Definition TypeTools.hpp:421