Go to the documentation of this file.
30 #define CLI11_PARSE(app, argc, argv) \
32 (app).parse((argc), (argv)); \
33 } catch(const CLI::ParseError &e) { \
34 return (app).exit(e); \
43 namespace FailureMessage {
54 using App_p = std::shared_ptr<App>;
147 using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
250 App(std::string app_description, std::string app_name,
App *parent)
288 explicit App(std::string app_description =
"", std::string app_name =
"")
289 :
App(app_description, app_name, nullptr) {
290 set_help_flag(
"-h,--help",
"Print this help message and exit");
293 App(
const App &) =
delete;
297 virtual ~App() =
default;
364 throw(
OptionAlreadyAdded(
"alias already matches an existing subcommand: " + app_name));
463 throw OptionAlreadyAdded(
"ignore case would cause subcommand name conflicts: " + match);
497 throw OptionAlreadyAdded(
"ignore underscore would cause subcommand name conflicts: " + match);
512 formatter_ = std::make_shared<FormatterLambda>(fmt);
548 std::string option_description =
"",
549 bool defaulted =
false,
550 std::function<std::string()> func = {}) {
551 Option myopt{option_name, option_description, option_callback,
this};
558 option.reset(
new Option(option_name, option_description, option_callback,
this));
561 option->default_function(func);
565 option->capture_default_str();
571 if(!defaulted && option->get_always_capture_default())
572 option->capture_default_str();
578 auto &matchname = opt->matching_name(myopt);
579 if(!matchname.empty()) {
588 template <
typename AssignTo,
589 typename ConvertTo = AssignTo,
593 std::string option_description =
"",
594 bool defaulted =
false) {
597 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
600 Option *opt =
add_option(option_name, fun, option_description, defaulted, [&variable]() {
601 return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
603 opt->
type_name(detail::type_name<ConvertTo>());
608 opt->
type_size((std::max)(Tcount, XCcount));
615 template <
typename T>
617 const std::function<
void(
const T &)> &func,
618 std::string option_description =
"") {
622 bool result = detail::lexical_conversion<T, T>(res, variable);
629 Option *opt =
add_option(option_name, std::move(fun), option_description,
false);
642 template <
typename T,
658 if(!flag_name.empty()) {
675 if(!help_name.empty()) {
685 Option *_add_flag_internal(std::string flag_name,
CLI::callback_t fun, std::string flag_description) {
691 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
692 for(
const auto &fname : flag_defaults)
693 opt->
fnames_.push_back(fname.first);
696 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
700 auto pos_name = opt->
get_name(
true);
702 throw IncorrectConstruction::PositionalFlag(pos_name);
717 template <
typename T,
721 return _add_flag_internal(flag_name,
CLI::callback_t(), flag_description);
726 template <
typename T,
730 std::string flag_description =
"") {
734 detail::sum_flag_vector(res, flag_count);
735 }
catch(
const std::invalid_argument &) {
740 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
746 template <
typename T,
749 !std::is_constructible<std::function<
void(
int)>, T>::value,
753 std::string flag_description =
"") {
762 template <
typename T,
765 std::vector<T> &flag_results,
766 std::string flag_description =
"") {
769 for(
const auto &elem : res) {
770 flag_results.emplace_back();
775 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
782 std::function<
void(
void)>
function,
783 std::string flag_description =
"") {
788 if(result && trigger) {
793 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
798 std::function<
void(int64_t)>
function,
799 std::string flag_description =
"") {
802 int64_t flag_count = 0;
803 detail::sum_flag_vector(res, flag_count);
804 function(flag_count);
807 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
814 std::function<
void(int64_t)>
function,
815 std::string flag_description =
"") {
816 return add_flag_function(std::move(flag_name), std::move(
function), std::move(flag_description));
821 template <
typename T>
825 std::string option_description =
"") {
827 Option *opt =
add_option(option_name, member, std::move(option_description));
833 template <
typename T>
836 const std::set<T> &options,
837 std::string option_description =
"") {
839 Option *opt =
add_option(option_name, member, std::move(option_description));
845 template <
typename T>
849 std::string option_description,
852 Option *opt =
add_option(option_name, member, std::move(option_description), defaulted);
858 template <
typename T>
861 const std::set<T> &options,
862 std::string option_description,
865 Option *opt =
add_option(option_name, member, std::move(option_description), defaulted);
871 template <
typename T,
typename XC =
double>
874 std::string option_description =
"",
875 bool defaulted =
false,
876 std::string label =
"COMPLEX") {
881 if(res.size() >= 2 && !res[1].empty()) {
883 if(str1.back() ==
'i' || str1.back() ==
'j')
887 auto str1 = res.front();
888 auto nloc = str1.find_last_of(
'-');
889 if(nloc != std::string::npos && nloc > 0) {
891 str1 = str1.substr(nloc);
892 if(str1.back() ==
'i' || str1.back() ==
'j')
896 if(str1.back() ==
'i' || str1.back() ==
'j') {
911 auto default_function = [&variable]() {
return CLI::detail::checked_to_string<T, T>(variable); };
914 add_option(option_name, std::move(fun), std::move(option_description), defaulted, default_function);
922 std::string default_filename =
"",
923 const std::string &help_message =
"Read an ini file",
924 bool config_required =
false) {
933 if(!option_name.empty()) {
935 if(config_required) {
938 if(!default_filename.empty()) {
951 op->remove_needs(opt);
952 op->remove_excludes(opt);
962 if(iterator != std::end(
options_)) {
970 template <
typename T = Option_group>
972 auto option_group = std::make_shared<T>(std::move(group_description), group_name,
nullptr);
973 auto ptr = option_group.get();
975 App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
985 App *
add_subcommand(std::string subcommand_name =
"", std::string subcommand_description =
"") {
989 CLI::App_p subcom = std::shared_ptr<App>(
new App(std::move(subcommand_description), subcommand_name,
this));
1000 throw(
OptionAlreadyAdded(
"subcommand name or alias matches existing subcommand: " + mstrg));
1002 subcom->parent_ =
this;
1011 sub->remove_excludes(subcom);
1012 sub->remove_needs(subcom);
1015 auto iterator = std::find_if(
1026 if(subcom ==
nullptr)
1029 if(subcomptr.get() == subcom)
1030 return subcomptr.get();
1044 auto uindex =
static_cast<unsigned>(index);
1053 if(subcom ==
nullptr)
1056 if(subcomptr.get() == subcom)
1064 if(subcomptr->check_name(subcom))
1072 auto uindex =
static_cast<unsigned>(index);
1082 if(app->name_.empty() && app->group_ == group_name) {
1099 cnt += opt->
count();
1102 cnt += sub->count_all();
1183 explicit operator bool()
const {
return parsed_ > 0; }
1216 void parse(
int argc,
const char *
const *argv) {
1223 std::vector<std::string> args;
1224 args.reserve(
static_cast<std::size_t
>(argc) - 1);
1225 for(
int i = argc - 1; i > 0; i--)
1226 args.emplace_back(argv[i]);
1227 parse(std::move(args));
1234 void parse(std::string commandline,
bool program_name_included =
false) {
1236 if(program_name_included) {
1242 commandline = std::move(nstr.second);
1246 if(!commandline.empty()) {
1254 args.erase(std::remove(args.begin(), args.end(), std::string{}), args.end());
1255 std::reverse(args.begin(), args.end());
1257 parse(std::move(args));
1262 void parse(std::vector<std::string> &args) {
1282 void parse(std::vector<std::string> &&args) {
1307 int exit(
const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr)
const {
1345 std::vector<const App *> subcomms(
subcommands_.size());
1351 subcomms.erase(std::remove_if(std::begin(subcomms),
1353 [&filter](
const App *app) {
return !filter(app); }),
1354 std::end(subcomms));
1370 std::remove_if(std::begin(subcomms), std::end(subcomms), [&filter](
App *app) {
return !filter(app); }),
1371 std::end(subcomms));
1388 if(opt ==
nullptr) {
1397 if(app ==
nullptr) {
1412 if(opt ==
nullptr) {
1420 if(app ==
nullptr) {
1446 auto other_app = *iterator;
1448 other_app->remove_excludes(
this);
1478 footer_ = std::move(footer_string);
1488 std::string
config_to_str(
bool default_also =
false,
bool write_description =
false)
const {
1502 if(!selected_subcommands.empty()) {
1503 return selected_subcommands.at(0)->help(prev, mode);
1505 return formatter_->make_help(
this, prev, mode);
1533 std::vector<const Option *>
get_options(
const std::function<
bool(
const Option *)> filter = {})
const {
1534 std::vector<const Option *> options(
options_.size());
1540 options.erase(std::remove_if(std::begin(options),
1542 [&filter](
const Option *opt) {
return !filter(opt); }),
1551 std::vector<Option *> options(
options_.size());
1558 std::remove_if(std::begin(options), std::end(options), [&filter](Option *opt) {
return !filter(opt); }),
1574 if(subc->get_name().empty()) {
1575 auto opt = subc->get_option_no_throw(option_name);
1576 if(opt !=
nullptr) {
1593 if(subc->get_name().empty()) {
1594 auto opt = subc->get_option_no_throw(option_name);
1595 if(opt !=
nullptr) {
1606 if(opt ==
nullptr) {
1615 if(opt ==
nullptr) {
1727 std::string local_name =
name_;
1737 if(local_name == name_to_check) {
1747 if(les == name_to_check) {
1756 std::vector<std::string> groups;
1760 if(std::find(groups.begin(), groups.end(), opt->
get_group()) == groups.end()) {
1772 std::vector<std::string>
remaining(
bool recurse =
false)
const {
1773 std::vector<std::string> miss_list;
1774 for(
const std::pair<detail::Classifier, std::string> &miss :
missing_) {
1775 miss_list.push_back(std::get<1>(miss));
1781 if(sub->name_.empty() && !sub->missing_.empty()) {
1782 for(
const std::pair<detail::Classifier, std::string> &miss : sub->missing_) {
1783 miss_list.push_back(std::get<1>(miss));
1791 std::vector<std::string> output = sub->remaining(recurse);
1792 std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list));
1800 std::vector<std::string> miss_list =
remaining(recurse);
1801 std::reverse(std::begin(miss_list), std::end(miss_list));
1807 auto remaining_options =
static_cast<std::size_t
>(std::count_if(
1808 std::begin(
missing_), std::end(
missing_), [](
const std::pair<detail::Classifier, std::string> &val) {
1814 remaining_options += sub->remaining_size(recurse);
1817 return remaining_options;
1835 opt->get_required();
1837 if(pcount - pcount_req > 1) {
1842 std::size_t nameless_subs{0};
1845 if(app->get_name().empty())
1852 throw(
InvalidError(
"Required min options greater than required max options",
1857 throw(
InvalidError(
"Required min options greater than number of available options",
1873 if(app->has_automatic_name_) {
1876 if(app->name_.empty()) {
1877 app->fallthrough_ =
false;
1878 app->prefix_command_ =
false;
1881 app->parent_ =
this;
1894 subc->run_callback(
true);
1898 if(subc->name_.empty() && subc->count_all() > 0) {
1899 subc->run_callback(
true);
1918 if(com !=
nullptr) {
1927 std::string dummy1, dummy2;
1936 if(dummy1[0] >=
'0' && dummy1[0] <=
'9') {
1945 if((current ==
"++") && !
name_.empty() &&
parent_ !=
nullptr)
1958 if(config_file.empty()) {
1959 if(config_required) {
1960 throw FileError::Missing(
"no specified config file");
1974 if(config_required || file_given)
1977 }
else if(config_required || file_given) {
1978 throw FileError::Missing(config_file);
1987 char *buffer =
nullptr;
1988 std::string ename_string;
1993 if(_dupenv_s(&buffer, &sz, opt->
envname_.c_str()) == 0 && buffer !=
nullptr) {
1994 ename_string = std::string(buffer);
1999 buffer = std::getenv(opt->
envname_.c_str());
2000 if(buffer !=
nullptr)
2001 ename_string = std::string(buffer);
2004 if(!ename_string.empty()) {
2011 if(sub->get_name().empty() || !sub->parse_complete_callback_)
2012 sub->_process_env();
2021 if(sub->get_name().empty() && sub->parse_complete_callback_) {
2022 if(sub->count_all() > 0) {
2023 sub->_process_callbacks();
2024 sub->run_callback();
2035 if(!sub->parse_complete_callback_) {
2036 sub->_process_callbacks();
2048 if(help_ptr !=
nullptr && help_ptr->
count() > 0)
2049 trigger_help =
true;
2050 if(help_all_ptr !=
nullptr && help_all_ptr->
count() > 0)
2051 trigger_all_help =
true;
2056 sub->_process_help_flags(trigger_help, trigger_all_help);
2059 }
else if(trigger_all_help) {
2061 }
else if(trigger_help) {
2069 bool excluded{
false};
2070 std::string excluder;
2072 if(opt->
count() > 0) {
2078 if(subc->count_all() > 0) {
2080 excluder = subc->get_display_name();
2092 bool missing_needed{
false};
2093 std::string missing_need;
2095 if(opt->
count() == 0) {
2096 missing_needed =
true;
2101 if(subc->count_all() == 0) {
2102 missing_needed =
true;
2103 missing_need = subc->get_display_name();
2106 if(missing_needed) {
2114 std::size_t used_options = 0;
2117 if(opt->
count() != 0) {
2126 if(opt->
count() > 0 && opt_req->
count() == 0)
2147 if(sub->name_.empty() && sub->count_all() > 0) {
2154 if(option_list.compare(0, 10,
"-h,--help,") == 0) {
2155 option_list.erase(0, 10);
2158 if(!subc_list.empty()) {
2168 if(sub->name_.empty() && sub->required_ ==
false) {
2169 if(sub->count_all() == 0) {
2182 if(sub->count() > 0 || sub->name_.empty()) {
2183 sub->_process_requirements();
2186 if(sub->required_ && sub->count_all() == 0) {
2205 if(num_left_over > 0) {
2211 if(sub->count() > 0)
2212 sub->_process_extras();
2221 if(num_left_over > 0) {
2228 if(sub->count() > 0)
2229 sub->_process_extras(args);
2237 if(sub->get_name().empty())
2238 sub->increment_parsed();
2242 void _parse(std::vector<std::string> &args) {
2245 bool positional_only =
false;
2247 while(!args.empty()) {
2271 void _parse(std::vector<std::string> &&args) {
2276 bool positional_only =
false;
2278 while(!args.empty()) {
2294 throw ConfigError::Extras(item.fullname());
2300 if(level < item.
parents.size()) {
2303 auto result = subcom->_parse_single_config(item, level + 1);
2311 if(item.
name ==
"++") {
2322 if(item.
name ==
"--") {
2340 throw ConfigError::NotConfigurable(item.
fullname());
2364 switch(classifier) {
2367 positional_only =
true;
2392 positional_only =
true;
2397 throw HorribleError(
"unrecognized classifier (you should not see this!)");
2405 std::size_t retval = 0;
2433 const std::string &positional = args.back();
2437 auto arg_rem = args.size();
2439 if(arg_rem <= remreq) {
2444 std::string pos = positional;
2445 pos = opt->_validate(pos, 0);
2464 std::string pos = positional;
2465 pos = opt->_validate(pos, 0);
2478 if((subc->name_.empty()) && (!subc->disabled_)) {
2479 if(subc->_parse_positional(args,
false)) {
2480 if(!subc->pre_parse_called_) {
2481 subc->_trigger_pre_parse(args.size());
2494 if(haltOnSubcommand) {
2505 if(com !=
nullptr && (com->parent_->require_subcommand_max_ == 0 ||
2506 com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) {
2521 while(!args.empty()) {
2534 if(com->disabled_ && ignore_disabled)
2536 if(com->get_name().empty()) {
2537 auto subc = com->
_find_subcommand(subc_name, ignore_disabled, ignore_used);
2538 if(subc !=
nullptr) {
2542 if(com->check_name(subc_name)) {
2543 if((!*com) || !ignore_used)
2560 if(com !=
nullptr) {
2564 auto parent_app = com->parent_;
2565 while(parent_app !=
this) {
2566 parent_app->_trigger_pre_parse(args.size());
2567 parent_app->parsed_subcommands_.push_back(com);
2568 parent_app = parent_app->parent_;
2574 throw HorribleError(
"Subcommand " + args.back() +
" missing");
2582 std::string current = args.back();
2584 std::string arg_name;
2588 switch(current_type) {
2591 throw HorribleError(
"Long parsed but missing (you should not see this):" + args.back());
2595 throw HorribleError(
"Short parsed but missing! You should not see this");
2599 throw HorribleError(
"windows option parsed but missing! You should not see this");
2606 throw HorribleError(
"parsing got called with invalid option! You should not see this");
2612 return opt->check_lname(arg_name);
2614 return opt->check_sname(arg_name);
2616 return opt->check_lname(arg_name) || opt->check_sname(arg_name);
2622 if(subc->name_.empty() && !subc->disabled_) {
2623 if(subc->_parse_arg(args, current_type)) {
2624 if(!subc->pre_parse_called_) {
2625 subc->_trigger_pre_parse(args.size());
2649 int min_num = (std::min)(op->get_type_size_min(), op->get_items_expected_min());
2650 int max_num = op->get_items_expected_max();
2654 int result_count = 0;
2657 auto res = op->get_flag_value(arg_name, value);
2658 op->add_result(res);
2660 }
else if(!value.empty()) {
2661 op->add_result(value, result_count);
2663 collected += result_count;
2665 }
else if(!rest.empty()) {
2666 op->add_result(rest, result_count);
2669 collected += result_count;
2673 while(min_num > collected && !args.empty()) {
2674 std::string current_ = args.back();
2676 op->add_result(current_, result_count);
2678 collected += result_count;
2681 if(min_num > collected) {
2682 throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
2685 if(max_num > collected || op->get_allow_extra_args()) {
2688 while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
2691 if(remreqpos >= args.size()) {
2695 op->add_result(args.back(), result_count);
2698 collected += result_count;
2705 if(min_num == 0 && max_num > 0 && collected == 0) {
2706 auto res = op->get_flag_value(arg_name, std::string{});
2707 op->add_result(res);
2713 if(min_num > 0 && op->get_type_size_max() != min_num && collected % op->get_type_size_max() != 0) {
2714 op->add_result(std::string{});
2719 args.push_back(rest);
2732 if(!
name_.empty()) {
2748 auto fallthrough_parent =
parent_;
2749 while((fallthrough_parent->parent_ !=
nullptr) && (fallthrough_parent->get_name().empty())) {
2750 fallthrough_parent = fallthrough_parent->
parent_;
2752 return fallthrough_parent;
2757 static const std::string estring;
2762 if(subc.get() != &subcom) {
2763 if(subc->disabled_) {
2767 if(subc->check_name(subcom.
get_name())) {
2771 if(!subc->get_name().empty()) {
2773 return subc->get_name();
2776 for(
const auto &les : subcom.
aliases_) {
2777 if(subc->check_name(les)) {
2782 for(
const auto &les : subc->aliases_) {
2788 if(subc->get_name().empty()) {
2790 if(!cmpres.empty()) {
2797 if(!cmpres.empty()) {
2808 missing_.emplace_back(val_type, val);
2813 if(subc->name_.empty() && subc->allow_extras_) {
2814 subc->missing_.emplace_back(val_type, val);
2819 missing_.emplace_back(val_type, val);
2825 if(opt ==
nullptr) {
2831 if(app == subc.get()) {
2847 if(iterator != std::end(
options_)) {
2848 const auto &opt_p = *iterator;
2850 return (*v == *opt_p);
2853 app->
options_.push_back(std::move(*iterator));
2868 :
App(std::move(group_description),
"", parent) {
2892 subc->get_parent()->remove_subcommand(subcom);
2905 inline void TriggerOn(
App *trigger_app, std::vector<App *> apps_to_enable) {
2906 for(
auto &app : apps_to_enable) {
2907 app->enabled_by_default(
false);
2908 app->disabled_by_default();
2912 for(
auto &app : apps_to_enable) {
2913 app->disabled(
false);
2927 for(
auto &app : apps_to_enable) {
2928 app->disabled_by_default(
false);
2929 app->enabled_by_default();
2933 for(
auto &app : apps_to_enable) {
2941 Validator deprecate_warning{[opt, replacement](std::string &) {
2942 std::cout << opt->
get_name() <<
" is deprecated please use '" << replacement
2944 return std::string();
2947 deprecate_warning.application_index(0);
2948 opt->
check(deprecate_warning);
2949 if(!replacement.empty()) {
2975 auto opt2 = app->
add_option(option_copy->get_name(
false,
true),
"option has been retired and has no effect")
2978 ->
type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max())
2979 ->
expected(option_copy->get_expected_min(), option_copy->get_expected_max())
2982 Validator retired_warning{[opt2](std::string &) {
2983 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
2984 return std::string();
2987 retired_warning.application_index(0);
2988 opt2->check(retired_warning);
2998 if(opt !=
nullptr) {
3002 auto opt2 = app->
add_option(option_name,
"option has been retired and has no effect")
3006 Validator retired_warning{[opt2](std::string &) {
3007 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
3008 return std::string();
3011 retired_warning.application_index(0);
3012 opt2->check(retired_warning);
3018 namespace FailureMessage {
3022 std::string header = std::string(e.what()) +
"\n";
3023 std::vector<std::string> names;
3034 header +=
"Run with " +
detail::join(names,
" or ") +
" for more information.\n";
3041 std::string header = std::string(
"ERROR: ") + e.
get_name() +
": " + e.what() +
"\n";
3042 header += app->
help();
3053 template <
typename... Args>
3056 return app->_parse_arg(std::forward<Args>(args)...);
3060 template <
typename... Args>
3063 return app->_parse_subcommand(std::forward<Args>(args)...);
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.hpp:2756
App * allow_windows_style_options(bool value=true)
Definition: App.hpp:472
std::shared_ptr< App > App_p
Definition: App.hpp:54
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition: App.hpp:2890
bool get_disabled() const
Get the status of disabled.
Definition: App.hpp:1673
bool fallthrough_
Allow subcommand fallthrough, so that parent commands can collect commands after subcommand....
Definition: App.hpp:189
void _process_config_file()
Read and process a configuration file (main app only)
Definition: App.hpp:1953
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition: App.hpp:192
bool check_name(std::string name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
Definition: Option.hpp:836
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:380
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition: App.hpp:245
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)
Definition: App.hpp:3040
std::string name
This is the name.
Definition: ConfigFwd.hpp:24
App * alias(std::string app_name)
Set an alias for the app.
Definition: App.hpp:354
Thrown when parsing an INI file and it is missing.
Definition: Error.hpp:175
const Option * get_option_no_throw(std::string option_name) const noexcept
Get an option by name (noexcept const version)
Definition: App.hpp:1585
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:2882
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition: App.hpp:72
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition: App.hpp:116
bool get_required() const
True if this is a required option.
Definition: Option.hpp:115
App & operator=(const App &)=delete
bool remove_excludes(App *app)
Removes a subcommand from the excludes list of this subcommand.
Definition: App.hpp:1441
This class is simply to allow tests access to App's protected functions.
Definition: App.hpp:3050
enabler
Simple empty scoped class.
Definition: TypeTools.hpp:22
bool prefix_command_
If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
Definition: App.hpp:85
constexpr int expected_max_vector_size
Definition: StringTools.hpp:36
Option * get_help_ptr()
Get a pointer to the help flag.
Definition: App.hpp:1690
missing_t missing_
Definition: App.hpp:152
void _configure()
Definition: App.hpp:1866
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition: App.hpp:433
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.hpp:1533
std::set< App * > need_subcommands_
Definition: App.hpp:169
Thrown when an excludes option is present.
Definition: Error.hpp:276
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.hpp:1799
App * add_subcommand(CLI::App_p subcom)
Add a previously created app as a subcommand.
Definition: App.hpp:994
Some validators that are provided.
Definition: Validators.hpp:61
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition: App.hpp:186
App * get_subcommand(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
Definition: App.hpp:1035
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition: App.hpp:985
-h or –help on command line
Definition: Error.hpp:156
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition: App.hpp:511
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition: Option.hpp:243
bool get_immediate_callback() const
Get the status of disabled.
Definition: App.hpp:1676
const Option * get_option(std::string option_name) const
Get an option by name.
Definition: App.hpp:1604
bool remove_needs(App *app)
Removes a subcommand from the needs list of this subcommand.
Definition: App.hpp:1463
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.hpp:921
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.hpp:546
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.hpp:1926
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
Definition: App.hpp:414
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition: App.hpp:223
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition: App.hpp:2884
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.
Definition: App.hpp:1307
config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition: App.hpp:1687
App * footer(std::string footer_string)
Set footer.
Definition: App.hpp:1477
Option * description(std::string option_description)
Set the description.
Definition: Option.hpp:714
App * require_subcommand(int value)
Definition: App.hpp:1126
Option * add_option_function(std::string option_name, const std::function< void(const T &)> &func, std::string option_description="")
Add option for a callback of a specific type.
Definition: App.hpp:616
Option * config_ptr_
Pointer to the config option.
Definition: App.hpp:242
void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
Definition: App.hpp:2967
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition: App.hpp:1396
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition: App.hpp:427
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition: App.hpp:1378
void parse(int argc, const char *const *argv)
Definition: App.hpp:1216
std::size_t count() const
Definition: App.hpp:1092
const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition: App.hpp:1714
std::vector< std::string > fnames_
a list of flag names with specified default values;
Definition: Option.hpp:246
bool get_enabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1682
bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition: App.hpp:1631
const std::string & get_name() const
Get the name of the current app.
Definition: App.hpp:1711
Option * add_set(std::string option_name, T &member, std::set< T > options, std::string option_description="")
Add set of options (No default, temp reference, such as an inline set) DEPRECATED.
Definition: App.hpp:822
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Definition: App.hpp:490
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition: App.hpp:50
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
Definition: App.hpp:948
int get_type_size_max() const
The maximum number of arguments the option expects.
Definition: Option.hpp:656
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition: App.hpp:478
std::string get_display_name() const
Get a display name for an app.
Definition: App.hpp:1723
App * final_callback(std::function< void()> app_callback)
Definition: App.hpp:316
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition: App.hpp:2234
int get_type_size_min() const
The minimum number of arguments the option expects.
Definition: Option.hpp:654
const Option * get_config_ptr() const
Get a pointer to the config option. (const)
Definition: App.hpp:1702
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:3054
App * needs(Option *opt)
Definition: App.hpp:1411
const std::string & get_group() const
Get the group of this subcommand.
Definition: App.hpp:1646
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
Definition: App.hpp:336
bool get_positional() const
True if the argument can be given directly.
Definition: Option.hpp:702
App * require_option(int value)
Definition: App.hpp:1155
bool get_configurable() const
The status of configurable.
Definition: Option.hpp:124
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition: App.hpp:2067
App * get_subcommand(int index=0) const
Get a pointer to subcommand by index.
Definition: App.hpp:1042
std::size_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition: App.hpp:217
void _parse_config(std::vector< ConfigItem > &args)
Definition: App.hpp:2291
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition: App.hpp:104
@ TakeLast
take only the last Expected number of arguments
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition: App.hpp:147
std::size_t count() const
Count the total number of times an option was passed.
Definition: Option.hpp:345
startup_mode
Definition: App.hpp:202
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTools.hpp:33
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="", bool defaulted=false)
Add option for assigning to a variable.
Definition: App.hpp:591
CLI::App_p get_subcommand_ptr(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
Definition: App.hpp:1062
bool get_disabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1679
std::vector< std::pair< std::string, std::string > > get_default_flag_values(const std::string &str)
extract default flag values either {def} or starting with a !
Definition: Split.hpp:71
std::set< Option * > needs_
A list of options that are required with this option.
Definition: Option.hpp:291
void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
Definition: App.hpp:2919
void _validate() const
Definition: App.hpp:1827
Option * type_size(int option_type_size)
Set a custom option size.
Definition: Option.hpp:1022
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition: App.hpp:1387
Extension of App to better manage groups of options.
Definition: App.hpp:2865
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app.
Definition: App.hpp:91
void parse(std::vector< std::string > &&args)
The real work is done here. Expects a reversed vector.
Definition: App.hpp:1282
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition: App.hpp:1482
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition: App.hpp:751
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
Definition: App.hpp:1566
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...
Definition: Option.hpp:727
Option * expected(int value)
Set the number of expected arguments.
Definition: Option.hpp:364
bool check_name(std::string name_to_check) const
Check the name, case insensitive and underscore insensitive if set.
Definition: App.hpp:1726
Option * add_mutable_set(std::string option_name, T &member, const std::set< T > &options, std::string option_description, bool defaulted)
Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED.
Definition: App.hpp:859
virtual ~App()=default
virtual destructor
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:764
std::vector< App * > get_subcommands(const std::function< bool(App *)> &filter)
Definition: App.hpp:1362
App * require_subcommand(std::size_t min, std::size_t max)
Definition: App.hpp:1139
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.hpp:650
int get_expected_max() const
The max number of times the option expects to be included.
Definition: Option.hpp:688
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition: App.hpp:3066
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:56
std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition: App.hpp:1336
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.hpp:1912
config_extras_mode allow_config_extras_
Definition: App.hpp:82
const std::string & get_name() const
Get the name of the Validator.
Definition: Validators.hpp:143
bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition: App.hpp:1637
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition: Option.hpp:294
void run_callback(bool final_mode=false)
Internal function to run (App) callback, bottom up.
Definition: App.hpp:1886
std::string fullname() const
The list of parents and name joined by ".".
Definition: ConfigFwd.hpp:30
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition: App.hpp:158
path_type check_path(const char *file) noexcept
get the type of the path from a file name
Definition: Validators.hpp:308
std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition: App.hpp:1513
App * parse_complete_callback(std::function< void()> pc_callback)
Definition: App.hpp:323
App * _get_fallthrough_parent()
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
Definition: App.hpp:2744
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition: App.hpp:138
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:222
int get_exit_code() const
Definition: Error.hpp:68
std::string envname_
If given, check the environment for this option.
Definition: Option.hpp:252
bool ignore_case_
If true, the program name is not case sensitive INHERITABLE.
Definition: App.hpp:183
Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error c...
Definition: Error.hpp:169
bool lexical_cast(const std::string &input, T &output)
Signed integers.
Definition: TypeTools.hpp:596
@ TakeAll
just get all the passed argument regardless
void parse(std::string commandline, bool program_name_included=false)
Definition: App.hpp:1234
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:392
bool get_configurable() const
Check the status of the allow windows style options.
Definition: App.hpp:1643
bool get_required() const
Get the status of required.
Definition: App.hpp:1670
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition: App.hpp:141
App * group(std::string group_name)
Changes the group membership.
Definition: App.hpp:1111
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition: App.hpp:208
bool valid_name_string(const std::string &str)
Verify an option name.
Definition: StringTools.hpp:181
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition: App.hpp:1696
void _process()
Process callbacks and such.
Definition: App.hpp:2193
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition: App.hpp:229
bool got_subcommand(std::string subcommand_name) const
Check with name instead of pointer to see if subcommand was selected.
Definition: App.hpp:1384
std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition: App.hpp:1652
std::vector< std::string > split_up(std::string str, char delimiter='\0')
Definition: StringTools.hpp:282
App * clear_aliases()
clear all the aliases of the current App
Definition: App.hpp:1717
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
Definition: App.hpp:2044
bool get_allow_extras() const
Get the status of allow extras.
Definition: App.hpp:1667
std::pair< std::string, std::string > split_program_name(std::string commandline)
Definition: Validators.hpp:1100
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition: App.hpp:109
bool immediate_callback_
Definition: App.hpp:101
App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
Definition: App.hpp:1080
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
Definition: App.hpp:2824
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition: Option.hpp:74
constexpr enabler dummy
An instance to use in EnableIf.
Definition: TypeTools.hpp:25
std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+)
Definition: App.hpp:3021
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition: App.hpp:161
App * prefix_command(bool allow=true)
Do not parse anything after the first unrecognized option and return.
Definition: App.hpp:450
bool get_prefix_command() const
Get the prefix command status.
Definition: App.hpp:1664
std::string get_name() const
Definition: Error.hpp:70
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition: App.hpp:220
App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition: App.hpp:2532
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition: App.hpp:200
std::vector< std::string > inputs
Listing of inputs.
Definition: ConfigFwd.hpp:27
CRTP * delimiter(char value='\0')
Allow in a configuration file.
Definition: Option.hpp:183
bool split_short(const std::string ¤t, std::string &name, std::string &rest)
Definition: Split.hpp:17
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:88
Option * check(Validator validator, const std::string &validator_name="")
Adds a Validator with a built in type name.
Definition: Option.hpp:423
App * get_subcommand(const App *subcom) const
Definition: App.hpp:1025
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition: App.hpp:1755
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition: App.hpp:517
std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition: App.hpp:1519
App * fallthrough(bool value=true)
Definition: App.hpp:1176
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition: App.hpp:1146
App * require_option(std::size_t min, std::size_t max)
Definition: App.hpp:1168
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.hpp:667
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition: StringTools.hpp:272
virtual void pre_callback()
Definition: App.hpp:1192
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:1302
std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition: App.hpp:1516
std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition: App.hpp:1655
std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition: App.hpp:1772
All errors derive from this one.
Definition: Error.hpp:63
Thrown when an option already exists.
Definition: Error.hpp:128
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition: App.hpp:235
void remove_default_flag_values(std::string &flags)
Definition: StringTools.hpp:227
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition: App.hpp:645
void clear()
Reset the parsed data.
Definition: App.hpp:1199
std::string get_flag_value(const std::string &name, std::string input_value) const
Definition: Option.hpp:875
std::string get_description() const
Get the app or subcommand description.
Definition: App.hpp:1524
std::size_t get_require_option_min() const
Get the required min option value.
Definition: App.hpp:1658
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition: App.hpp:180
std::function< bool(const results_t &)> callback_t
callback function definition
Definition: Option.hpp:25
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
Definition: App.hpp:1431
std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition: App.hpp:2404
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition: App.hpp:94
bool _parse_subcommand(std::vector< std::string > &args)
Definition: App.hpp:2554
Definition: Option.hpp:228
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:374
std::string get_footer() const
Generate and return the footer.
Definition: App.hpp:1649
std::size_t get_require_option_max() const
Get the required max option value.
Definition: App.hpp:1661
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition: StringTools.hpp:196
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:288
Option * add_flag_function(std::string flag_name, std::function< void(int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
Definition: App.hpp:797
std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition: App.hpp:1488
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition: Option.hpp:1016
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1625
bool split_windows_style(const std::string ¤t, std::string &name, std::string &value)
Definition: Split.hpp:43
const App * get_parent() const
Get the parent of this subcommand (or nullptr if master app) (const version)
Definition: App.hpp:1708
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition: App.hpp:637
Option * add_flag(std::string flag_name, T &flag_count, std::string flag_description="")
Definition: App.hpp:728
startup_mode default_startup
Definition: App.hpp:205
App * needs(App *app)
Definition: App.hpp:1419
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition: Option.hpp:628
Check to see if something is bool (fail check by default)
Definition: TypeTools.hpp:54
ConfigBase ConfigINI
the default Config is the INI file format
Definition: ConfigFwd.hpp:113
std::string remove_underscore(std::string str)
remove underscores from a string
Definition: StringTools.hpp:204
Verify items are in a set.
Definition: Validators.hpp:684
bool get_ignore_case() const
Check the status of ignore_case.
Definition: App.hpp:1628
void parse(std::vector< std::string > &args)
Definition: App.hpp:1262
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition: App.hpp:226
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition: App.hpp:330
Option * run_callback_for_default(bool value=true)
Definition: Option.hpp:415
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
Definition: App.hpp:1453
App * parent_
A pointer to the parent if this is a subcommand.
Definition: App.hpp:214
AppFormatMode
Definition: FormatterFwd.hpp:22
const std::string & get_description() const
Get the description.
Definition: Option.hpp:711
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition: App.hpp:155
bool get_callback_run() const
See if the callback has been run already.
Definition: Option.hpp:1003
std::vector< App * > get_subcommands() const
Definition: App.hpp:1340
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:2874
std::string & trim(std::string &str)
Trim whitespace from string.
Definition: StringTools.hpp:127
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition: App.hpp:126
std::string description_
Description of the current program/subcommand.
Definition: App.hpp:75
std::vector< Option_p > options_
The list of options, stored locally.
Definition: App.hpp:119
std::set< Option * > need_options_
Definition: App.hpp:173
std::vector< std::string > results_t
Definition: Option.hpp:23
Option * get_config_ptr()
Get a pointer to the config option.
Definition: App.hpp:1699
Creates a command line program, with very few defaults.
Definition: App.hpp:61
std::set< Option * > exclude_options_
Definition: App.hpp:165
void _parse(std::vector< std::string > &&args)
Internal parse function.
Definition: App.hpp:2271
Thrown when validation fails before parsing.
Definition: Error.hpp:309
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition: App.hpp:2299
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition: App.hpp:505
bool required_
True if this is a required option.
Definition: Option.hpp:50
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition: App.hpp:2725
T as() const
Return the results as the specified type.
Definition: Option.hpp:996
bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition: App.hpp:523
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition: App.hpp:2361
Definition: Option.hpp:191
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1622
const std::string & get_group() const
Get the group of this option.
Definition: Option.hpp:112
void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
Definition: App.hpp:2940
const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition: App.hpp:1769
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition: Option.hpp:177
void _process_extras()
Throw an error if anything is left over and should not be.
Definition: App.hpp:2202
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition: Option.hpp:1075
std::unique_ptr< Option > Option_p
Definition: Option.hpp:30
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:971
void _process_callbacks()
Process callbacks. Runs on all subcommands.
Definition: App.hpp:2017
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition: App.hpp:2431
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type)
Definition: App.hpp:2580
bool get_validate_positionals() const
Get the status of validating positionals.
Definition: App.hpp:1684
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
Definition: App.hpp:1008
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
Definition: App.hpp:456
Option * add_complex(std::string option_name, T &variable, std::string option_description="", bool defaulted=false, std::string label="COMPLEX")
Add a complex number.
Definition: App.hpp:872
bool empty() const
True if the option was not passed.
Definition: Option.hpp:348
int get_items_expected_min() const
The total min number of expected string values to be used.
Definition: Option.hpp:691
This will only trigger for actual void type.
Definition: TypeTools.hpp:318
std::vector< const App * > get_subcommands(const std::function< bool(const App *)> &filter) const
Definition: App.hpp:1344
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.hpp:2806
Option * add_flag(std::string flag_name, T &flag_description)
Definition: App.hpp:720
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.hpp:781
Usually something like –help-all on command line.
Definition: Error.hpp:162
const Option * get_help_ptr() const
Get a pointer to the help flag. (const)
Definition: App.hpp:1693
void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
Definition: App.hpp:2898
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition: App.hpp:1984
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition: App.hpp:250
Definition: Error.hpp:318
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition: App.hpp:78
Thrown when a required option is missing.
Definition: Error.hpp:205
std::size_t escape_detect(std::string &str, std::size_t offset)
Definition: StringTools.hpp:349
Option_group(std::string group_description, std::string group_name, App *parent)
Definition: App.hpp:2867
bool get_allow_extra_args() const
Get the current value of allow extra args.
Definition: Option.hpp:411
This will only trigger for actual void type.
Definition: TypeTools.hpp:297
bool get_fallthrough() const
Check the status of fallthrough.
Definition: App.hpp:1634
App * callback(std::function< void()> app_callback)
Definition: App.hpp:305
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition: App.hpp:97
bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition: App.hpp:1640
Thrown when counting a non-existent option.
Definition: Error.hpp:326
std::size_t count_all() const
Definition: App.hpp:1096
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:3061
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition: App.hpp:386
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition: App.hpp:107
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition: App.hpp:712
int get_expected_min() const
The number of times the option expects to be included.
Definition: Option.hpp:686
CRTP * required(bool value=true)
Set the option as required.
Definition: Option.hpp:96
Option * add_mutable_set(std::string option_name, T &member, const std::set< T > &options, std::string option_description="")
Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED.
Definition: App.hpp:834
void clear()
Clear the parsed results (mostly for testing)
Definition: Option.hpp:354
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition: App.hpp:444
void _process_extras(std::vector< std::string > &args)
Definition: App.hpp:2218
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition: App.hpp:135
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition: App.hpp:2242
bool split_long(const std::string ¤t, std::string &name, std::string &value)
Definition: Split.hpp:27
App * get_parent()
Get the parent of this subcommand (or nullptr if master app)
Definition: App.hpp:1705
Option * add_result(std::string s)
Puts a result at the end.
Definition: Option.hpp:919
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition: App.hpp:132
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition: App.hpp:484
Holds values to load into Options.
Definition: ConfigFwd.hpp:19
Classifier
Definition: App.hpp:39
App * description(std::string app_description)
Set the description of the app.
Definition: App.hpp:1527
std::string group_
The group membership INHERITABLE.
Definition: App.hpp:232
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:129
Option * get_option(std::string option_name)
Get an option by name (non-const version)
Definition: App.hpp:1613
std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition: App.hpp:1494
std::vector< Option * > get_options(const std::function< bool(Option *)> filter={})
Non-const version of the above.
Definition: App.hpp:1550
std::vector< std::string > parents
This is the list of parents.
Definition: ConfigFwd.hpp:21
void run_callback()
Process the callback.
Definition: Option.hpp:787
App * enabled_by_default(bool enable=true)
Definition: App.hpp:403
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition: App.hpp:1117
CLI::App_p get_subcommand_ptr(int index=0) const
Get an owning pointer to subcommand by index.
Definition: App.hpp:1070
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.hpp:1052
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition: Error.hpp:86
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition: App.hpp:211
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition: App.hpp:526
Thrown when a requires option is missing.
Definition: Error.hpp:269
bool has_default_flag_values(const std::string &flags)
check if the flag definitions has possible false flags
Definition: StringTools.hpp:223
Option * allow_extra_args(bool value=true)
Definition: Option.hpp:406
std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition: App.hpp:1806
bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition: App.hpp:2418
Option * add_set(std::string option_name, T &member, std::set< T > options, std::string option_description, bool defaulted)
Add set of options (with default, static set, such as an inline set) DEPRECATED.
Definition: App.hpp:846