27#include "ConfigFwd.hpp"
29#include "FormatterFwd.hpp"
33#include "StringTools.hpp"
34#include "TypeTools.hpp"
40#define CLI11_PARSE(app, ...) \
42 (app).parse(__VA_ARGS__); \
43 } catch(const CLI::ParseError &e) { \
44 return (app).exit(e); \
49enum class Classifier : std::uint8_t {
61namespace FailureMessage {
63CLI11_INLINE std::string simple(
const App *app,
const Error &e);
66CLI11_INLINE std::string help(
const App *app,
const Error &e);
70enum class ExtrasMode : std::uint8_t {
75 AssumeMultipleArguments,
80enum class ConfigExtrasMode : std::uint8_t {
Error = 0, Ignore, IgnoreAll, Capture };
83enum class config_extras_mode : std::uint8_t { error = 0, ignore, ignore_all, capture };
89enum class PrefixCommandMode : std::uint8_t { Off = 0, SeparatorOnly = 1, On = 2, PositionalOnly = 3 };
93using App_p = std::shared_ptr<App>;
98template <typename T, enable_if_t<!std::is_integral<T>::value || (
sizeof(T) <= 1U), detail::enabler> = detail::dummy>
99Option *default_flag_modifiers(Option *opt) {
100 return opt->always_capture_default();
104template <typename T, enable_if_t<std::is_integral<T>::value && (
sizeof(T) > 1U), detail::enabler> = detail::dummy>
105Option *default_flag_modifiers(Option *opt) {
106 return opt->multi_option_policy(MultiOptionPolicy::Sum)->default_str(
"0")->force_callback();
211 using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
270 enum class startup_mode : std::uint8_t { stable, enabled,
disabled };
332 std::vector<std::string> normalized_argv_{};
335 std::vector<char *> normalized_argv_view_{};
339 App(std::string app_description, std::string app_name,
App *parent);
346 explicit App(std::string app_description =
"", std::string app_name =
"");
348 App(
const App &) =
delete;
349 App &operator=(
const App &) =
delete;
387 App *
name(std::string app_name =
"");
394 allow_extras_ = allow ? ExtrasMode::Capture : ExtrasMode::Error;
475 prefix_command_ = is_prefix ? PrefixCommandMode::On : PrefixCommandMode::Off;
518 formatter_ = std::make_shared<FormatterLambda>(fmt);
553 callback_t option_callback,
554 std::string option_description =
"",
555 bool defaulted =
false,
556 std::function<std::string()> func = {});
559 template <
typename AssignTo,
560 typename ConvertTo = AssignTo,
561 enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
564 std::string option_description =
"") {
566 auto fun = [&variable](
const CLI::results_t &res) {
567 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
570 Option *opt =
add_option(option_name, fun, option_description,
false, [&variable]() {
571 return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
573 opt->
type_name(detail::type_name<ConvertTo>());
576 auto Tcount = detail::type_count<AssignTo>::value;
577 auto XCcount = detail::type_count<ConvertTo>::value;
578 opt->
type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
579 opt->
expected(detail::expected_count<ConvertTo>::value);
585 template <typename AssignTo, enable_if_t<!std::is_const<AssignTo>::value, detail::enabler> = detail::dummy>
588 std::string option_description =
"") {
590 auto fun = [&variable](
const CLI::results_t &res) {
591 return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
594 Option *opt =
add_option(option_name, fun, option_description,
false, []() {
return std::string{}; });
595 opt->
type_name(detail::type_name<AssignTo>());
596 opt->
type_size(detail::type_count_min<AssignTo>::value, detail::type_count<AssignTo>::value);
597 opt->
expected(detail::expected_count<AssignTo>::value);
603 template <
typename ArgType>
605 const std::function<
void(
const ArgType &)> &func,
606 std::string option_description =
"") {
608 auto fun = [func](
const CLI::results_t &res) {
610 bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
617 Option *opt =
add_option(option_name, std::move(fun), option_description,
false);
618 opt->
type_name(detail::type_name<ArgType>());
619 opt->
type_size(detail::type_count_min<ArgType>::value, detail::type_count<ArgType>::value);
620 opt->
expected(detail::expected_count<ArgType>::value);
628 template <
typename T,
629 enable_if_t<std::is_const<T>::value && std::is_constructible<std::string, T>::value, detail::enabler> =
631 Option *
add_option(std::string option_name, T &option_description) {
632 return add_option(option_name, CLI::callback_t(), option_description,
false);
636 Option *
set_help_flag(std::string flag_name =
"",
const std::string &help_description =
"");
643 const std::string &versionString =
"",
644 const std::string &version_help =
"Display program version information and exit");
648 std::function<std::string()> vfunc,
649 const std::string &version_help =
"Display program version information and exit");
653 Option *_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description);
662 template <
typename T,
663 enable_if_t<(std::is_const<typename std::remove_reference<T>::type>::value ||
664 std::is_rvalue_reference<T &&>::value) &&
665 std::is_constructible<std::string,
typename std::remove_reference<T>::type>::value,
666 detail::enabler> = detail::dummy>
667 Option *
add_flag(std::string flag_name, T &&flag_description) {
668 return _add_flag_internal(flag_name, CLI::callback_t(), std::forward<T>(flag_description));
673 template <
typename T,
674 enable_if_t<!detail::is_mutable_container<T>::value && !std::is_const<T>::value &&
675 !std::is_constructible<std::function<void(
int)>, T>::value,
676 detail::enabler> = detail::dummy>
679 std::string flag_description =
"") {
681 CLI::callback_t fun = [&flag_result](
const CLI::results_t &res) {
682 using CLI::detail::lexical_cast;
683 return lexical_cast(res[0], flag_result);
685 auto *opt = _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
686 return detail::default_flag_modifiers<T>(opt);
690 template <
typename T,
691 enable_if_t<!std::is_assignable<std::function<void(std::int64_t)> &, T>::value, detail::enabler> =
694 std::vector<T> &flag_results,
695 std::string flag_description =
"") {
696 CLI::callback_t fun = [&flag_results](
const CLI::results_t &res) {
698 for(
const auto &elem : res) {
699 using CLI::detail::lexical_cast;
700 flag_results.emplace_back();
701 retval &= lexical_cast(elem, flag_results.back());
705 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
712 std::function<
void(
void)> function,
713 std::string flag_description =
"");
717 std::function<
void(std::int64_t)> function,
718 std::string flag_description =
"");
723 std::function<
void(std::int64_t)> function,
724 std::string flag_description =
"") {
725 return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
730 Option *
set_config(std::string option_name =
"",
731 std::string default_filename =
"",
732 const std::string &help_message =
"Read an ini file",
733 bool config_required =
false);
739 template <
typename T = Option_group>
741 if(!detail::valid_alias_name_string(group_name)) {
744 auto option_group = std::make_shared<T>(std::move(group_description), group_name,
this);
745 option_group->fallthrough(
false);
746 auto *ptr = option_group.get();
748 App_p app_ptr = std::static_pointer_cast<App>(option_group);
750 app_ptr->footer_ =
"";
751 app_ptr->set_help_flag();
761 App *
add_subcommand(std::string subcommand_name =
"", std::string subcommand_description =
"");
802 CLI11_NODISCARD std::size_t
count_all()
const;
806 group_ = std::move(group_name);
865 explicit operator bool()
const {
return parsed_ > 0; }
885 void parse(
int argc,
const char *
const *argv);
886 void parse(
int argc,
const wchar_t *
const *argv);
889 template <
class CharT>
void parse_char_t(
int argc,
const CharT *
const *argv);
896 void parse(std::string commandline,
bool program_name_included =
false);
897 void parse(std::wstring commandline,
bool program_name_included =
false);
901 void parse(std::vector<std::string> &args);
904 void parse(std::vector<std::string> &&args);
906 void parse_from_stream(std::istream &input);
914 int exit(
const Error &e, std::ostream &out, std::ostream &err)
const;
921 int exit(
const Error &e, std::ostream &out)
const;
936 std::vector<const App *>
get_subcommands(
const std::function<
bool(
const App *)> &filter)
const;
946 CLI11_NODISCARD
bool got_subcommand(std::string subcommand_name)
const noexcept;
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) {
998 CLI11_NODISCARD std::string
config_to_str(ConfigOutputMode mode,
bool write_description =
false)
const;
1003 CLI11_NODISCARD std::string
config_to_str(
bool default_also,
bool write_description =
false)
const;
1007 CLI11_NODISCARD std::string
help(std::string prev =
"", AppFormatMode mode = AppFormatMode::Normal)
const;
1010 CLI11_NODISCARD std::string
version()
const;
1024#if CLI11_USE_STATIC_RTTI == 0
1041 std::vector<const Option *>
get_options(
const std::function<
bool(
const Option *)> filter = {})
const;
1044 std::vector<Option *>
get_options(
const std::function<
bool(Option *)> filter = {});
1050 CLI11_NODISCARD
const Option *
get_option_no_throw(std::string option_name)
const noexcept;
1053 CLI11_NODISCARD
const Option *
get_option(std::string option_name)
const;
1056 CLI11_NODISCARD Option *
get_option(std::string option_name);
1089 CLI11_NODISCARD std::string
get_usage()
const;
1092 CLI11_NODISCARD std::string
get_footer()
const;
1191 CLI11_NODISCARD std::string
get_display_name(
bool with_aliases =
false)
const;
1195 CLI11_NODISCARD
bool check_name(std::string name_to_check)
const;
1198 enum class NameMatch : std::uint8_t { none = 0, exact = 1, prefix = 2 };
1206 CLI11_NODISCARD std::vector<std::string>
get_groups()
const;
1212 CLI11_NODISCARD std::vector<std::string>
remaining(
bool recurse =
false)
const;
1218 CLI11_NODISCARD std::size_t
remaining_size(
bool recurse =
false)
const;
1235 void run_callback(
bool final_mode =
false,
bool suppress_final_callback =
false);
1238 CLI11_NODISCARD
bool _valid_subcommand(
const std::string ¤t,
bool ignore_used =
true)
const;
1241 CLI11_NODISCARD detail::Classifier
_recognize(
const std::string ¤t,
1242 bool ignore_used_subcommands =
true)
const;
1261 void _process_help_flags(CallbackPriority priority,
bool trigger_help =
false,
bool trigger_all_help =
false)
const;
1286 void _parse(std::vector<std::string> &args);
1289 void _parse(std::vector<std::string> &&args);
1308 bool _parse_single(std::vector<std::string> &args,
bool &positional_only);
1323 CLI11_NODISCARD
App *
1324 _find_subcommand(
const std::string &subc_name,
bool ignore_disabled,
bool ignore_used)
const noexcept;
1335 bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type,
bool local_processing_only);
1350 void _move_to_missing(detail::Classifier val_type, const std::
string &val);
1358class Option_group : public
App {
1360 Option_group(std::string group_description, std::string group_name,
App *parent);
1367 template <
typename... Args>
void add_options(Option *opt, Args... args) {
1377CLI11_INLINE
void TriggerOn(
App *trigger_app,
App *app_to_enable);
1380CLI11_INLINE
void TriggerOn(
App *trigger_app, std::vector<App *> apps_to_enable);
1383CLI11_INLINE
void TriggerOff(
App *trigger_app,
App *app_to_enable);
1386CLI11_INLINE
void TriggerOff(
App *trigger_app, std::vector<App *> apps_to_enable);
1389CLI11_INLINE
void deprecate_option(Option *opt,
const std::string &replacement =
"");
1392CLI11_INLINE
void deprecate_option(
App *app,
const std::string &option_name,
const std::string &replacement =
"");
1395CLI11_INLINE
void deprecate_option(
App &app,
const std::string &option_name,
const std::string &replacement =
"");
1398CLI11_INLINE
void retire_option(
App *app, Option *opt);
1401CLI11_INLINE
void retire_option(
App &app, Option *opt);
1404CLI11_INLINE
void retire_option(
App *app,
const std::string &option_name);
1407CLI11_INLINE
void retire_option(
App &app,
const std::string &option_name);
1415 template <
typename... Args>
static decltype(
auto)
parse_arg(
App *app, Args &&...args) {
1416 return app->
_parse_arg(std::forward<Args>(args)...);
1420 template <
typename... Args>
static decltype(
auto)
parse_subcommand(
App *app, Args &&...args) {
1425 template <
typename... Args>
1428 return app->
_parse_arg(std::forward<Args>(args)...);
1432 template <
typename... Args>
1449#ifndef CLI11_COMPILE
1450#include "impl/App_inl.hpp"
Creates a command line program, with very few defaults.
Definition App.hpp:115
CLI11_NODISCARD Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version).
Definition App_inl.hpp:1077
bool subcommand_fallthrough_
Allow subcommands to fallthrough, so that parent commands can trigger other subcommands after subcomm...
Definition App.hpp:257
CLI11_NODISCARD std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition App_inl.hpp:950
CLI11_NODISCARD std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition App_inl.hpp:1225
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1059
CLI11_NODISCARD bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition App_inl.hpp:2002
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition App.hpp:502
CLI11_NODISCARD bool get_allow_subcommand_prefix_matching() const
Get the status of allowing prefix matching for subcommands.
Definition App.hpp:1131
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.
Definition App_inl.hpp:1337
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
Definition App_inl.hpp:170
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
Definition App_inl.hpp:330
bool allow_non_standard_options_
indicator that the subcommand should allow non-standard option arguments, such as -single_dash_flag
Definition App.hpp:289
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition App_inl.hpp:946
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:1140
Option * config_ptr_
Pointer to the config option.
Definition App.hpp:323
CLI11_NODISCARD bool get_allow_non_standard_option_names() const
Get the status of allowing non standard option names.
Definition App.hpp:1128
CLI11_NODISCARD bool get_configurable() const
Check the status of the allow windows style options.
Definition App.hpp:1083
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:586
CLI11_NODISCARD std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition App.hpp:1016
App * subcommand_fallthrough(bool value=true)
Set subcommand fallthrough, set to true so that subcommands on parents are recognized.
Definition App.hpp:858
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition App.hpp:523
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
Definition App_inl.hpp:2586
CLI11_NODISCARD App * _get_fallthrough_parent() noexcept
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
Definition App_inl.hpp:2509
std::size_t require_option_min_
Minimum required options (not inheritable!).
Definition App.hpp:304
NameMatch
enumeration of matching possibilities
Definition App.hpp:1198
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition App.hpp:417
App * clear_aliases()
clear all the aliases of the current App
Definition App.hpp:1185
CLI11_NODISCARD bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition App.hpp:1068
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Definition App_inl.hpp:196
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition App.hpp:393
App * fallthrough(bool value=true)
Definition App.hpp:852
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition App.hpp:301
Option * get_config_ptr()
Get a pointer to the config option.
Definition App.hpp:1161
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition App.hpp:244
CLI11_NODISCARD std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition App_inl.hpp:1193
CLI11_NODISCARD bool get_allow_extras() const
Get the status of allow extras.
Definition App.hpp:1113
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.
Definition App_inl.hpp:1219
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition App.hpp:295
CLI11_NODISCARD App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
Definition App_inl.hpp:611
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition App.hpp:811
std::string usage_
Usage to put after program/subcommand description in the help output INHERITABLE.
Definition App.hpp:181
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition App.hpp:171
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_inl.hpp:142
CLI11_NODISCARD const Option * get_version_ptr() const
Get a pointer to the version option. (const).
Definition App.hpp:1170
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition App_inl.hpp:1506
App * allow_extras(ExtrasMode allow)
Remove the error when extras are left over on the command line.
Definition App.hpp:399
CLI11_NODISCARD std::size_t count_all() const
Definition App_inl.hpp:620
void _parse_setup()
Definition App_inl.hpp:717
CLI11_NODISCARD bool get_fallthrough() const
Check the status of fallthrough.
Definition App.hpp:1071
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition App.hpp:148
CLI11_NODISCARD bool get_prefix_command() const
Get the prefix command status.
Definition App.hpp:1107
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition App.hpp:562
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1098
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.
Definition App_inl.hpp:363
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app.
Definition App.hpp:145
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
Definition App_inl.hpp:912
CLI11_NODISCARD std::string get_usage() const
Generate and return the usage.
Definition App_inl.hpp:942
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1062
CLI11_NODISCARD bool get_immediate_callback() const
Get the status of disabled.
Definition App.hpp:1134
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1152
void _configure()
Definition App_inl.hpp:1274
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition App_inl.hpp:1990
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.
Definition App_inl.hpp:443
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition App.hpp:532
void parse(int argc, const char *const *argv)
Definition App_inl.hpp:650
void _process_config_file()
Read and process a configuration file (main app only).
Definition App_inl.hpp:1394
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition App.hpp:187
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition App_inl.hpp:1693
CLI11_NODISCARD bool check_name(std::string name_to_check) const
Definition App_inl.hpp:1137
CLI11_NODISCARD const Option * get_option(std::string option_name) const
Get an option by name.
Definition App_inl.hpp:1048
App * required(bool require=true)
Set whether this subcommand/option-group is required to be present on the command line.
Definition App.hpp:405
Option * version_ptr_
A pointer to a version flag if there is one.
Definition App.hpp:199
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const).
Definition App.hpp:1158
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
Definition App_inl.hpp:541
App * parent_
A pointer to the parent if this is a subcommand.
Definition App.hpp:310
Option * add_flag(std::string flag_name, T &&flag_description)
Definition App.hpp:667
std::set< Option * > exclude_options_
Definition App.hpp:229
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition App_inl.hpp:2491
App * group(std::string group_name)
Changes the group membership.
Definition App.hpp:805
App * enabled_by_default(bool enable=true)
Definition App_inl.hpp:151
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.
Definition App_inl.hpp:586
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:190
ExtrasMode allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition App.hpp:132
PrefixCommandMode prefix_command_
If true, cease processing on an unrecognized option (implies allow_extras) INHERITABLE.
Definition App.hpp:139
int exit(const Error &e, std::ostream &out, std::ostream &err) const
Print a nice error message and return the exit code.
Definition App_inl.hpp:756
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition App.hpp:161
CLI11_NODISCARD bool get_subcommand_fallthrough() const
Check the status of subcommand fallthrough.
Definition App.hpp:1074
virtual void pre_callback()
Definition App.hpp:874
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:740
App * get_parent()
Get the parent of this subcommand (or nullptr if main app).
Definition App.hpp:1173
void _validate() const
Definition App_inl.hpp:1239
std::string name_
Subcommand name or program name (from parser if name is empty).
Definition App.hpp:126
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition App.hpp:222
CLI11_NODISCARD const Option * get_help_ptr() const
Get a pointer to the help flag. (const).
Definition App.hpp:1155
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition App.hpp:250
App * allow_windows_style_options(bool value=true)
Definition App.hpp:490
missing_t missing_
Definition App.hpp:216
CLI11_NODISCARD bool get_validate_positionals() const
Get the status of validating positionals.
Definition App.hpp:1142
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:604
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
Definition App_inl.hpp:1294
bool allow_prefix_matching_
indicator to allow subcommands to match with prefix matching
Definition App.hpp:292
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!).
Definition App.hpp:298
App * usage(std::string usage_string)
Set usage.
Definition App.hpp:974
CLI11_NODISCARD NameMatch check_name_detail(std::string name_to_check) const
Definition App_inl.hpp:1142
App * allow_subcommand_prefix_matching(bool allowed=true)
allow prefix matching for subcommands
Definition App.hpp:429
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition App_inl.hpp:1430
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition App.hpp:205
void _parse_stream(std::istream &input)
Internal function to parse a stream.
Definition App_inl.hpp:1770
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition App_inl.hpp:1121
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:909
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:142
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...
Definition App_inl.hpp:2531
void clear()
Reset the parsed data.
Definition App_inl.hpp:634
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1104
App * footer(std::string footer_string)
Set footer.
Definition App.hpp:984
App * get_subcommand(const App *subcom) const
Definition App_inl.hpp:557
CLI11_NODISCARD std::string version() const
Displays a version string.
Definition App_inl.hpp:964
virtual ~App()=default
virtual destructor
CLI11_NODISCARD App * get_subcommand_no_throw(std::string subcom) const noexcept
Definition App_inl.hpp:573
CLI11_NODISCARD std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition App.hpp:928
bool _add_flag_like_result(Option *op, const ConfigItem &item, const std::vector< std::string > &inputs)
store the results for a flag like option
Definition App_inl.hpp:1789
std::vector< Option_p > options_
The list of options, stored locally.
Definition App.hpp:174
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition App.hpp:196
bool validate_optional_arguments_
If set to true optional vector arguments are validated before assigning INHERITABLE.
Definition App.hpp:282
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition App_inl.hpp:160
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition App.hpp:164
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
Definition App_inl.hpp:487
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition App.hpp:831
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition App_inl.hpp:37
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:184
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition App_inl.hpp:510
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition App.hpp:381
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.
Definition App_inl.hpp:426
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition App.hpp:268
void _process()
Process callbacks and such.
Definition App_inl.hpp:1634
bool immediate_callback_
Definition App.hpp:155
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition App_inl.hpp:1941
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name).
Definition App_inl.hpp:107
CLI11_NODISCARD std::string config_to_str() const
Definition App_inl.hpp:930
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
Definition App_inl.hpp:2609
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition App.hpp:1119
void _process_extras()
Throw an error if anything is left over and should not be.
Definition App_inl.hpp:1673
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.
Definition App_inl.hpp:1321
CLI11_NODISCARD PrefixCommandMode get_prefix_command_mode() const
Get the prefix command status.
Definition App.hpp:1110
CLI11_NODISCARD bool get_ignore_case() const
Check the status of ignore_case.
Definition App.hpp:1065
App * parse_complete_callback(std::function< void()> pc_callback)
Definition App.hpp:374
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition App.hpp:276
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order).
Definition App_inl.hpp:1180
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition App.hpp:517
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1182
void _parse_config(const std::vector< ConfigItem > &args)
Definition App_inl.hpp:1781
App * description(std::string app_description)
Set the description of the app.
Definition App.hpp:1035
CLI11_NODISCARD std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition App.hpp:1022
std::string description_
Description of the current program/subcommand.
Definition App.hpp:129
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition App_inl.hpp:840
App * allow_non_standard_option_names(bool allowed=true)
allow non standard option names
Definition App.hpp:423
CLI11_NODISCARD bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition App.hpp:1080
Option * get_version_ptr()
Get a pointer to the version option.
Definition App.hpp:1167
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1101
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable).
Definition App.hpp:307
CLI11_NODISCARD bool get_disabled() const
Get the status of disabled.
Definition App.hpp:1122
CLI11_NODISCARD bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition App.hpp:1077
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition App.hpp:316
CLI11_NODISCARD bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition App.hpp:529
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition App.hpp:225
void _process_completion_callbacks(bool with_help_flags)
Definition App_inl.hpp:1701
CLI11_NODISCARD bool get_disabled_by_default() const
Get the status of disabled by default.
Definition App.hpp:1137
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:693
ConfigExtrasMode allow_config_extras_
Definition App.hpp:136
CLI11_NODISCARD std::size_t count() const
Definition App.hpp:798
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition App_inl.hpp:2012
bool ignore_case_
If true, the program name is not case-sensitive INHERITABLE.
Definition App.hpp:247
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1086
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type, bool local_processing_only)
Definition App_inl.hpp:2224
bool silent_
Definition App.hpp:286
CLI11_NODISCARD const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version).
Definition App.hpp:1176
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition App.hpp:158
App * callback(std::function< void()> app_callback)
Definition App_inl.hpp:98
App * final_callback(std::function< void()> app_callback)
Definition App.hpp:367
std::string group_
The group membership INHERITABLE.
Definition App.hpp:313
App * alias(std::string app_name)
Set an alias for the app.
Definition App_inl.hpp:124
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition App.hpp:151
CLI11_NODISCARD ExtrasMode get_allow_extras_mode() const
Get the mode of allow_extras.
Definition App.hpp:1116
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition App.hpp:444
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition App.hpp:193
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.
Definition App_inl.hpp:458
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition App.hpp:989
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
Definition App_inl.hpp:182
CLI11_NODISCARD std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition App.hpp:1019
App * prefix_command(PrefixCommandMode mode)
Set the prefix command mode directly.
Definition App.hpp:480
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
Definition App_inl.hpp:892
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:932
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition App.hpp:1147
App * allow_config_extras(ConfigExtrasMode mode)
ignore extras in config files
Definition App.hpp:465
bool _parse_subcommand(std::vector< std::string > &args)
Definition App_inl.hpp:2184
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition App.hpp:496
bool fallthrough_
Definition App.hpp:254
std::set< Option * > need_options_
Definition App.hpp:237
CLI11_NODISCARD bool get_validate_optional_arguments() const
Get the status of validating optional vector arguments.
Definition App.hpp:1144
CLI11_NODISCARD bool get_silent() const
Get the status of silence.
Definition App.hpp:1125
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...
Definition App_inl.hpp:982
std::set< App * > need_subcommands_
Definition App.hpp:233
App * validate_optional_arguments(bool validate=true)
Set the subcommand to validate optional vector arguments before assigning.
Definition App.hpp:450
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition App_inl.hpp:210
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition App.hpp:511
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition App.hpp:219
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition App.hpp:631
App * prefix_command(bool is_prefix=true)
Definition App.hpp:474
CLI11_NODISCARD const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition App.hpp:1209
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition App_inl.hpp:1729
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition App.hpp:279
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition App_inl.hpp:1850
void _process_help_flags(CallbackPriority priority, bool trigger_help=false, bool trigger_all_help=false) const
Definition App_inl.hpp:1481
startup_mode default_startup
Definition App.hpp:273
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition App.hpp:459
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition App.hpp:677
void _process_callbacks(CallbackPriority priority)
Process callbacks. Runs on all subcommands.
Definition App_inl.hpp:1452
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1032
App * require_option(std::size_t min, std::size_t max)
Definition App.hpp:844
CLI11_NODISCARD char ** ensure_utf8(char **argv)
Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
Definition App_inl.hpp:76
CLI11_NODISCARD App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition App_inl.hpp:2148
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1095
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition App_inl.hpp:422
CLI11_NODISCARD const Option * get_config_ptr() const
Get a pointer to the config option. (const).
Definition App.hpp:1164
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1179
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition App.hpp:411
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer).
Definition App.hpp:202
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.
Definition App_inl.hpp:346
App * require_subcommand(std::size_t min, std::size_t max)
Definition App.hpp:824
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition App.hpp:260
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer).
Definition App.hpp:326
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition App_inl.hpp:850
All errors derive from this one.
Definition Error.hpp:73
Thrown when an option is set to conflicting values (non-vector and multi args, for example).
Definition Error.hpp:97
Extension of App to better manage groups of options.
Definition App.hpp:1358
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition App.hpp:1367
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition App_inl.hpp:2667
Definition Option.hpp:218
Definition Option.hpp:261
Option * type_size(int option_type_size)
Set a custom option size.
Definition Option_inl.hpp:531
Option * expected(int value)
Set the number of expected arguments.
Definition Option_inl.hpp:56
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:388
Option * run_callback_for_default(bool value=true)
Definition Option.hpp:435
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy).
Definition Option_inl.hpp:280
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition Option_inl.hpp:587
Holds values to load into Options.
Definition ConfigFwd.hpp:29
This class is simply to allow tests access to App's protected functions.
Definition App.hpp:1411
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:1433
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition App.hpp:1439
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:1426
static const App * get_fallthrough_parent(const App *app)
Wrap the const fallthrough parent function to make sure that is working correctly.
Definition App.hpp:1442