38 #define CLI11_PARSE(app, argc, argv) \ 40 (app).parse((argc), (argv)); \ 41 } catch(const CLI::ParseError &e) { \ 42 return (app).exit(e); \ 51 namespace FailureMessage {
62 using App_p = std::shared_ptr<App>;
159 using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
266 App(std::string app_description, std::string app_name,
App *parent)
304 explicit App(std::string app_description =
"", std::string app_name =
"")
305 :
App(app_description, app_name, nullptr) {
306 set_help_flag(
"-h,--help",
"Print this help message and exit");
309 App(
const App &) =
delete;
313 virtual ~App() =
default;
379 throw(
OptionAlreadyAdded(
"alias already matches an existing subcommand: " + app_name));
484 throw OptionAlreadyAdded(
"ignore case would cause subcommand name conflicts: " + match);
518 throw OptionAlreadyAdded(
"ignore underscore would cause subcommand name conflicts: " + match);
533 formatter_ = std::make_shared<FormatterLambda>(fmt);
569 std::string option_description =
"",
570 bool defaulted =
false,
571 std::function<std::string()> func = {}) {
572 Option myopt{option_name, option_description, option_callback,
this};
579 option.reset(
new Option(option_name, option_description, option_callback,
this));
582 option->default_function(func);
586 option->capture_default_str();
592 if(!defaulted && option->get_always_capture_default())
593 option->capture_default_str();
599 auto &matchname = opt->matching_name(myopt);
600 if(!matchname.empty()) {
609 template <
typename AssignTo,
610 typename ConvertTo = AssignTo,
614 std::string option_description =
"") {
617 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
620 Option *opt =
add_option(option_name, fun, option_description,
false, [&variable]() {
621 return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
623 opt->
type_name(detail::type_name<ConvertTo>());
628 opt->
type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
629 opt->
expected(detail::expected_count<ConvertTo>::value);
638 std::string option_description =
"") {
641 return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
644 Option *opt =
add_option(option_name, fun, option_description,
false, []() {
return std::string{}; });
645 opt->
type_name(detail::type_name<AssignTo>());
647 opt->
expected(detail::expected_count<AssignTo>::value);
653 template <
typename ArgType>
655 const std::function<
void(
const ArgType &)> &func,
656 std::string option_description =
"") {
660 bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
667 Option *opt =
add_option(option_name, std::move(fun), option_description,
false);
668 opt->
type_name(detail::type_name<ArgType>());
670 opt->
expected(detail::expected_count<ArgType>::value);
680 template <
typename T,
696 if(!flag_name.empty()) {
713 if(!help_name.empty()) {
723 const std::string &versionString =
"",
724 const std::string &version_help =
"Display program version information and exit") {
732 if(!flag_name.empty()) {
734 flag_name, [versionString]() {
throw(
CLI::CallForVersion(versionString, 0)); }, version_help);
742 std::function<std::string()> vfunc,
743 const std::string &version_help =
"Display program version information and exit") {
750 if(!flag_name.empty()) {
761 Option *_add_flag_internal(std::string flag_name,
CLI::callback_t fun, std::string flag_description) {
767 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
768 for(
const auto &fname : flag_defaults)
769 opt->
fnames_.push_back(fname.first);
772 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
776 auto pos_name = opt->
get_name(
true);
778 throw IncorrectConstruction::PositionalFlag(pos_name);
793 template <
typename T,
797 return _add_flag_internal(flag_name,
CLI::callback_t(), flag_description);
802 template <
typename T,
807 std::string flag_description =
"") {
811 detail::sum_flag_vector(res, flag_count);
812 }
catch(
const std::invalid_argument &) {
817 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
823 template <
typename T,
826 !std::is_constructible<std::function<
void(
int)>, T>::value,
830 std::string flag_description =
"") {
839 template <
typename T,
843 std::vector<T> &flag_results,
844 std::string flag_description =
"") {
847 for(
const auto &elem : res) {
848 flag_results.emplace_back();
853 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
860 std::function<
void(
void)>
function,
861 std::string flag_description =
"") {
866 if(result && trigger) {
871 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
876 std::function<
void(std::int64_t)>
function,
877 std::string flag_description =
"") {
880 std::int64_t flag_count = 0;
881 detail::sum_flag_vector(res, flag_count);
882 function(flag_count);
885 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
892 std::function<
void(std::int64_t)>
function,
893 std::string flag_description =
"") {
894 return add_flag_function(std::move(flag_name), std::move(
function), std::move(flag_description));
900 std::string default_filename =
"",
901 const std::string &help_message =
"Read an ini file",
902 bool config_required =
false) {
911 if(!option_name.empty()) {
913 if(config_required) {
916 if(!default_filename.empty()) {
929 op->remove_needs(opt);
930 op->remove_excludes(opt);
940 if(iterator != std::end(
options_)) {
948 template <
typename T = Option_group>
953 auto option_group = std::make_shared<T>(std::move(group_description), group_name,
this);
954 auto ptr = option_group.get();
956 App_p app_ptr = std::dynamic_pointer_cast<
App>(option_group);
966 App *
add_subcommand(std::string subcommand_name =
"", std::string subcommand_description =
"") {
970 "Subcommand name starts with invalid character, '!' and '-' are not allowed");
972 for(
auto c : subcommand_name) {
975 "'), all characters are allowed except" 976 "'=',':','{','}', and ' '");
980 CLI::App_p subcom = std::shared_ptr<App>(
new App(std::move(subcommand_description), subcommand_name,
this));
991 throw(
OptionAlreadyAdded(
"subcommand name or alias matches existing subcommand: " + mstrg));
993 subcom->parent_ =
this;
1002 sub->remove_excludes(subcom);
1003 sub->remove_needs(subcom);
1006 auto iterator = std::find_if(
1017 if(subcom ==
nullptr)
1020 if(subcomptr.get() == subcom)
1021 return subcomptr.get();
1035 auto uindex =
static_cast<unsigned>(index);
1044 if(subcom ==
nullptr)
1047 if(subcomptr.get() == subcom)
1055 if(subcomptr->check_name(subcom))
1063 auto uindex =
static_cast<unsigned>(index);
1073 if(app->name_.empty() && app->group_ == group_name) {
1090 cnt += opt->
count();
1093 cnt += sub->count_all();
1174 explicit operator bool()
const {
return parsed_ > 0; }
1207 void parse(
int argc,
const char *
const *argv) {
1214 std::vector<std::string> args;
1215 args.reserve(static_cast<std::size_t>(argc) - 1);
1216 for(
int i = argc - 1; i > 0; i--)
1217 args.emplace_back(argv[i]);
1218 parse(std::move(args));
1225 void parse(std::string commandline,
bool program_name_included =
false) {
1227 if(program_name_included) {
1233 commandline = std::move(nstr.second);
1238 if(!commandline.empty()) {
1246 args.erase(std::remove(args.begin(), args.end(), std::string{}), args.end());
1247 std::reverse(args.begin(), args.end());
1249 parse(std::move(args));
1254 void parse(std::vector<std::string> &args) {
1274 void parse(std::vector<std::string> &&args) {
1309 int exit(
const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr)
const {
1315 if(e.
get_name() ==
"CallForHelp") {
1320 if(e.
get_name() ==
"CallForAllHelp") {
1325 if(e.
get_name() ==
"CallForVersion") {
1326 out << e.what() << std::endl;
1352 std::vector<const App *> subcomms(
subcommands_.size());
1358 subcomms.erase(std::remove_if(std::begin(subcomms),
1360 [&filter](
const App *app) {
return !filter(app); }),
1361 std::end(subcomms));
1377 std::remove_if(std::begin(subcomms), std::end(subcomms), [&filter](
App *app) {
return !filter(app); }),
1378 std::end(subcomms));
1395 if(opt ==
nullptr) {
1404 if(app ==
nullptr) {
1419 if(opt ==
nullptr) {
1427 if(app ==
nullptr) {
1453 auto other_app = *iterator;
1455 other_app->remove_excludes(
this);
1485 footer_ = std::move(footer_string);
1495 std::string
config_to_str(
bool default_also =
false,
bool write_description =
false)
const {
1509 if(!selected_subcommands.empty()) {
1510 return selected_subcommands.at(0)->help(prev, mode);
1512 return formatter_->make_help(
this, prev, mode);
1545 #if defined(__cpp_rtti) || (defined(__GXX_RTTI) && __GXX_RTTI) || (defined(_HAS_STATIC_RTTI) && (_HAS_STATIC_RTTI == 0)) 1562 std::vector<const Option *>
get_options(
const std::function<
bool(
const Option *)> filter = {})
const {
1563 std::vector<const Option *> options(
options_.size());
1569 options.erase(std::remove_if(std::begin(options),
1571 [&filter](
const Option *opt) {
return !filter(opt); }),
1580 std::vector<Option *> options(
options_.size());
1587 std::remove_if(std::begin(options), std::end(options), [&filter](Option *opt) {
return !filter(opt); }),
1603 if(subc->get_name().empty()) {
1604 auto opt = subc->get_option_no_throw(option_name);
1605 if(opt !=
nullptr) {
1622 if(subc->get_name().empty()) {
1623 auto opt = subc->get_option_no_throw(option_name);
1624 if(opt !=
nullptr) {
1635 if(opt ==
nullptr) {
1644 if(opt ==
nullptr) {
1763 return std::string(
"[Option Group: ") +
get_group() +
"]";
1765 if(
aliases_.empty() || !with_aliases) {
1768 std::string dispname =
name_;
1769 for(
const auto &lalias :
aliases_) {
1770 dispname.push_back(
',');
1771 dispname.push_back(
' ');
1772 dispname.append(lalias);
1779 std::string local_name =
name_;
1789 if(local_name == name_to_check) {
1799 if(les == name_to_check) {
1808 std::vector<std::string> groups;
1812 if(std::find(groups.begin(), groups.end(), opt->
get_group()) == groups.end()) {
1824 std::vector<std::string>
remaining(
bool recurse =
false)
const {
1825 std::vector<std::string> miss_list;
1826 for(
const std::pair<detail::Classifier, std::string> &miss :
missing_) {
1827 miss_list.push_back(std::get<1>(miss));
1833 if(sub->name_.empty() && !sub->missing_.empty()) {
1834 for(
const std::pair<detail::Classifier, std::string> &miss : sub->missing_) {
1835 miss_list.push_back(std::get<1>(miss));
1843 std::vector<std::string> output = sub->remaining(recurse);
1844 std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list));
1852 std::vector<std::string> miss_list =
remaining(recurse);
1853 std::reverse(std::begin(miss_list), std::end(miss_list));
1859 auto remaining_options =
static_cast<std::size_t
>(std::count_if(
1860 std::begin(
missing_), std::end(
missing_), [](
const std::pair<detail::Classifier, std::string> &val) {
1866 remaining_options += sub->remaining_size(recurse);
1869 return remaining_options;
1887 opt->get_required();
1889 if(pcount - pcount_req > 1) {
1894 std::size_t nameless_subs{0};
1897 if(app->get_name().empty())
1904 throw(
InvalidError(
"Required min options greater than required max options",
1909 throw(
InvalidError(
"Required min options greater than number of available options",
1925 if(app->has_automatic_name_) {
1928 if(app->name_.empty()) {
1929 app->fallthrough_ =
false;
1930 app->prefix_command_ =
false;
1933 app->parent_ =
this;
1939 void run_callback(
bool final_mode =
false,
bool suppress_final_callback =
false) {
1947 subc->run_callback(
true, suppress_final_callback);
1951 if(subc->name_.empty() && subc->count_all() > 0) {
1952 subc->run_callback(
true, suppress_final_callback);
1971 if(com !=
nullptr) {
1980 std::string dummy1, dummy2;
1989 if(dummy1[0] >=
'0' && dummy1[0] <=
'9') {
1998 if((current ==
"++") && !
name_.empty() &&
parent_ !=
nullptr)
2010 auto config_files =
config_ptr_->
as<std::vector<std::string>>();
2011 if(config_files.empty() || config_files.front().empty()) {
2012 if(config_required) {
2013 throw FileError::Missing(
"no specified config file");
2017 for(
auto rit = config_files.rbegin(); rit != config_files.rend(); ++rit) {
2018 const auto &config_file = *rit;
2028 if(config_required || file_given)
2031 }
else if(config_required || file_given) {
2032 throw FileError::Missing(config_file);
2042 char *buffer =
nullptr;
2043 std::string ename_string;
2048 if(_dupenv_s(&buffer, &sz, opt->
envname_.c_str()) == 0 && buffer !=
nullptr) {
2049 ename_string = std::string(buffer);
2054 buffer = std::getenv(opt->
envname_.c_str());
2055 if(buffer !=
nullptr)
2056 ename_string = std::string(buffer);
2059 if(!ename_string.empty()) {
2066 if(sub->get_name().empty() || !sub->parse_complete_callback_)
2067 sub->_process_env();
2076 if(sub->get_name().empty() && sub->parse_complete_callback_) {
2077 if(sub->count_all() > 0) {
2078 sub->_process_callbacks();
2079 sub->run_callback();
2090 if(!sub->parse_complete_callback_) {
2091 sub->_process_callbacks();
2103 if(help_ptr !=
nullptr && help_ptr->
count() > 0)
2104 trigger_help =
true;
2105 if(help_all_ptr !=
nullptr && help_all_ptr->
count() > 0)
2106 trigger_all_help =
true;
2111 sub->_process_help_flags(trigger_help, trigger_all_help);
2114 }
else if(trigger_all_help) {
2116 }
else if(trigger_help) {
2124 bool excluded{
false};
2125 std::string excluder;
2127 if(opt->
count() > 0) {
2133 if(subc->count_all() > 0) {
2135 excluder = subc->get_display_name();
2147 bool missing_needed{
false};
2148 std::string missing_need;
2150 if(opt->
count() == 0) {
2151 missing_needed =
true;
2156 if(subc->count_all() == 0) {
2157 missing_needed =
true;
2158 missing_need = subc->get_display_name();
2161 if(missing_needed) {
2169 std::size_t used_options = 0;
2172 if(opt->
count() != 0) {
2181 if(opt->
count() > 0 && opt_req->
count() == 0)
2202 if(sub->name_.empty() && sub->count_all() > 0) {
2210 return std::string{};
2212 return ptr->get_name(
false,
true);
2216 if(!subc_list.empty()) {
2226 if(sub->name_.empty() && sub->required_ ==
false) {
2227 if(sub->count_all() == 0) {
2240 if(sub->count() > 0 || sub->name_.empty()) {
2241 sub->_process_requirements();
2244 if(sub->required_ && sub->count_all() == 0) {
2253 bool caught_error{
false};
2262 caught_error =
true;
2280 if(num_left_over > 0) {
2286 if(sub->count() > 0)
2287 sub->_process_extras();
2296 if(num_left_over > 0) {
2303 if(sub->count() > 0)
2304 sub->_process_extras(args);
2312 if(sub->get_name().empty())
2313 sub->increment_parsed();
2317 void _parse(std::vector<std::string> &args) {
2320 bool positional_only =
false;
2322 while(!args.empty()) {
2346 void _parse(std::vector<std::string> &&args) {
2351 bool positional_only =
false;
2353 while(!args.empty()) {
2381 throw ConfigError::Extras(item.fullname());
2387 if(level < item.
parents.size()) {
2398 if(item.
name ==
"++") {
2409 if(item.
name ==
"--") {
2419 if(item.
name.size() == 1) {
2438 throw ConfigError::NotConfigurable(item.
fullname());
2463 switch(classifier) {
2466 positional_only =
true;
2491 positional_only =
true;
2496 throw HorribleError(
"unrecognized classifier (you should not see this!)");
2504 std::size_t retval = 0;
2532 const std::string &positional = args.back();
2536 auto arg_rem = args.size();
2538 if(arg_rem <= remreq) {
2543 std::string pos = positional;
2544 pos = opt->_validate(pos, 0);
2563 std::string pos = positional;
2564 pos = opt->_validate(pos, 0);
2577 if((subc->name_.empty()) && (!subc->disabled_)) {
2578 if(subc->_parse_positional(args,
false)) {
2579 if(!subc->pre_parse_called_) {
2580 subc->_trigger_pre_parse(args.size());
2593 if(haltOnSubcommand) {
2604 if(com !=
nullptr && (com->parent_->require_subcommand_max_ == 0 ||
2605 com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) {
2620 while(!args.empty()) {
2633 if(com->disabled_ && ignore_disabled)
2635 if(com->get_name().empty()) {
2636 auto subc = com->
_find_subcommand(subc_name, ignore_disabled, ignore_used);
2637 if(subc !=
nullptr) {
2641 if(com->check_name(subc_name)) {
2642 if((!*com) || !ignore_used)
2659 if(com !=
nullptr) {
2665 auto parent_app = com->parent_;
2666 while(parent_app !=
this) {
2667 parent_app->_trigger_pre_parse(args.size());
2669 parent_app->parsed_subcommands_.push_back(com);
2671 parent_app = parent_app->parent_;
2677 throw HorribleError(
"Subcommand " + args.back() +
" missing");
2685 std::string current = args.back();
2687 std::string arg_name;
2691 switch(current_type) {
2694 throw HorribleError(
"Long parsed but missing (you should not see this):" + args.back());
2698 throw HorribleError(
"Short parsed but missing! You should not see this");
2702 throw HorribleError(
"windows option parsed but missing! You should not see this");
2709 throw HorribleError(
"parsing got called with invalid option! You should not see this");
2715 return opt->check_lname(arg_name);
2717 return opt->check_sname(arg_name);
2719 return opt->check_lname(arg_name) || opt->check_sname(arg_name);
2725 if(subc->name_.empty() && !subc->disabled_) {
2726 if(subc->_parse_arg(args, current_type)) {
2727 if(!subc->pre_parse_called_) {
2728 subc->_trigger_pre_parse(args.size());
2752 if(op->get_inject_separator()) {
2753 if(!op->results().empty() && !op->results().back().empty()) {
2754 op->add_result(std::string{});
2760 int min_num = (std::min)(op->get_type_size_min(), op->get_items_expected_min());
2761 int max_num = op->get_items_expected_max();
2765 auto tmax = op->get_type_size_max();
2770 int result_count = 0;
2773 auto res = op->get_flag_value(arg_name, value);
2774 op->add_result(res);
2776 }
else if(!value.empty()) {
2777 op->add_result(value, result_count);
2779 collected += result_count;
2781 }
else if(!rest.empty()) {
2782 op->add_result(rest, result_count);
2785 collected += result_count;
2789 while(min_num > collected && !args.empty()) {
2790 std::string current_ = args.back();
2792 op->add_result(current_, result_count);
2794 collected += result_count;
2797 if(min_num > collected) {
2798 throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
2801 if(max_num > collected || op->get_allow_extra_args()) {
2804 while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
2807 if(remreqpos >= args.size()) {
2811 op->add_result(args.back(), result_count);
2814 collected += result_count;
2821 if(min_num == 0 && max_num > 0 && collected == 0) {
2822 auto res = op->get_flag_value(arg_name, std::string{});
2823 op->add_result(res);
2829 if(min_num > 0 && op->get_type_size_max() != min_num && (collected % op->get_type_size_max()) != 0) {
2830 op->add_result(std::string{});
2832 if(op->get_trigger_on_parse()) {
2837 args.push_back(rest);
2850 if(!
name_.empty()) {
2866 auto fallthrough_parent =
parent_;
2867 while((fallthrough_parent->parent_ !=
nullptr) && (fallthrough_parent->get_name().empty())) {
2868 fallthrough_parent = fallthrough_parent->
parent_;
2870 return fallthrough_parent;
2875 static const std::string estring;
2880 if(subc.get() != &subcom) {
2881 if(subc->disabled_) {
2885 if(subc->check_name(subcom.
get_name())) {
2889 if(!subc->get_name().empty()) {
2891 return subc->get_name();
2894 for(
const auto &les : subcom.
aliases_) {
2895 if(subc->check_name(les)) {
2900 for(
const auto &les : subc->aliases_) {
2906 if(subc->get_name().empty()) {
2908 if(!cmpres.empty()) {
2915 if(!cmpres.empty()) {
2926 missing_.emplace_back(val_type, val);
2931 if(subc->name_.empty() && subc->allow_extras_) {
2932 subc->missing_.emplace_back(val_type, val);
2937 missing_.emplace_back(val_type, val);
2943 if(opt ==
nullptr) {
2949 if(app == subc.get()) {
2965 if(iterator != std::end(
options_)) {
2966 const auto &opt_p = *iterator;
2968 return (*v == *opt_p);
2971 app->
options_.push_back(std::move(*iterator));
2986 :
App(
std::move(group_description),
"", parent) {
3010 subc->get_parent()->remove_subcommand(subcom);
3023 inline void TriggerOn(
App *trigger_app, std::vector<App *> apps_to_enable) {
3024 for(
auto &app : apps_to_enable) {
3025 app->enabled_by_default(
false);
3026 app->disabled_by_default();
3030 for(
auto &app : apps_to_enable) {
3031 app->disabled(
false);
3045 for(
auto &app : apps_to_enable) {
3046 app->disabled_by_default(
false);
3047 app->enabled_by_default();
3051 for(
auto &app : apps_to_enable) {
3059 Validator deprecate_warning{[opt, replacement](std::string &) {
3060 std::cout << opt->
get_name() <<
" is deprecated please use '" << replacement
3062 return std::string();
3065 deprecate_warning.application_index(0);
3066 opt->
check(deprecate_warning);
3067 if(!replacement.empty()) {
3093 auto opt2 = app->
add_option(option_copy->get_name(
false,
true),
"option has been retired and has no effect")
3095 ->default_str(
"RETIRED")
3096 ->type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max())
3097 ->expected(option_copy->get_expected_min(), option_copy->get_expected_max())
3098 ->allow_extra_args(option_copy->get_allow_extra_args());
3100 Validator retired_warning{[opt2](std::string &) {
3101 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
3102 return std::string();
3105 retired_warning.application_index(0);
3106 opt2->check(retired_warning);
3116 if(opt !=
nullptr) {
3120 auto opt2 = app->
add_option(option_name,
"option has been retired and has no effect")
3124 Validator retired_warning{[opt2](std::string &) {
3125 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
3126 return std::string();
3129 retired_warning.application_index(0);
3130 opt2->check(retired_warning);
3136 namespace FailureMessage {
3140 std::string header = std::string(e.what()) +
"\n";
3141 std::vector<std::string> names;
3152 header +=
"Run with " +
detail::join(names,
" or ") +
" for more information.\n";
3159 std::string header = std::string(
"ERROR: ") + e.
get_name() +
": " + e.what() +
"\n";
3160 header += app->
help();
3172 template <
typename... Args>
static decltype(
auto)
parse_arg(
App *app, Args &&...args) {
3173 return app->
_parse_arg(std::forward<Args>(args)...);
3177 template <
typename... Args>
static decltype(
auto)
parse_subcommand(
App *app, Args &&...args) {
3181 template <
typename... Args>
3185 return app->
_parse_arg(std::forward<Args>(args)...);
3189 template <
typename... Args>
App * clear_aliases()
clear all the aliases of the current App
Definition: App.hpp:1755
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:2942
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:1304
bool empty() const
True if the option was not passed.
Definition: Option.hpp:366
bool get_allow_extras() const
Get the status of allow extras.
Definition: App.hpp:1696
std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition: App.hpp:1684
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
Definition: App.hpp:1939
App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
Definition: App.hpp:1071
std::size_t get_require_option_min() const
Get the required min option value.
Definition: App.hpp:1687
This class is simply to allow tests access to App's protected functions.
Definition: App.hpp:3168
bool get_callback_run() const
See if the callback has been run already.
Definition: Option.hpp:1069
std::string get_name() const
Definition: Error.hpp:77
bool get_prefix_command() const
Get the prefix command status.
Definition: App.hpp:1693
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition: App.hpp:233
bool get_silent() const
Get the status of silence.
Definition: App.hpp:1705
std::size_t get_require_option_max() const
Get the required max option value.
Definition: App.hpp:1690
std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition: App.hpp:2503
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition: App.hpp:102
App * prefix_command(bool allow=true)
Do not parse anything after the first unrecognized option and return.
Definition: App.hpp:471
std::string get_footer() const
Generate and return the footer.
Definition: App.hpp:1678
int get_expected_min() const
The number of times the option expects to be included.
Definition: Option.hpp:734
bool _parse_subcommand(std::vector< std::string > &args)
Definition: App.hpp:2653
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition: App.hpp:538
CRTP * required(bool value=true)
Set the option as required.
Definition: Option.hpp:105
std::size_t count() const
Count the total number of times an option was passed.
Definition: Option.hpp:363
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1654
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:96
const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version)
Definition: App.hpp:1746
std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition: App.hpp:1543
Option * add_flag(std::string flag_name, T &flag_count, std::string flag_description="")
Definition: App.hpp:805
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition: App.hpp:58
App * needs(App *app)
Definition: App.hpp:1426
bool split_long(const std::string ¤t, std::string &name, std::string &value)
Definition: Split.hpp:35
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition: App.hpp:1137
App * require_option(std::size_t min, std::size_t max)
Definition: App.hpp:1159
const std::string & get_name() const
Get the name of the Validator.
Definition: Validators.hpp:159
const Option * get_version_ptr() const
Get a pointer to the version option. (const)
Definition: App.hpp:1740
const std::string & get_description() const
Get the description.
Definition: Option.hpp:759
startup_mode default_startup
Definition: App.hpp:217
std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition: App.hpp:1540
void parse(std::vector< std::string > &args)
Definition: App.hpp:1254
void clear()
Reset the parsed data.
Definition: App.hpp:1190
std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition: App.hpp:1824
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.hpp:722
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition: App.hpp:683
bool get_required() const
True if this is a required option.
Definition: Option.hpp:124
Classifier
Definition: App.hpp:47
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition: App.hpp:251
std::string get_description() const
Get the app or subcommand description.
Definition: App.hpp:1553
App * parent_
A pointer to the parent if this is a subcommand.
Definition: App.hpp:245
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition: App.hpp:407
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
Definition: App.hpp:1438
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition: App.hpp:192
int get_expected_max() const
The max number of times the option expects to be included.
Definition: Option.hpp:736
std::string description_
Description of the current program/subcommand.
Definition: App.hpp:83
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition: App.hpp:135
std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition: App.hpp:1495
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:389
std::set< Option * > need_options_
Definition: App.hpp:185
Option * version_ptr_
A pointer to a version flag if there is one.
Definition: App.hpp:147
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:304
bool check_name(const std::string &name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
Definition: Option.hpp:893
Option * get_config_ptr()
Get a pointer to the config option.
Definition: App.hpp:1731
std::vector< Option_p > options_
The list of options, stored locally.
Definition: App.hpp:128
void _parse(std::vector< std::string > &&args)
Internal parse function.
Definition: App.hpp:2346
std::string envname_
If given, check the environment for this option.
Definition: Option.hpp:261
std::vector< std::string > parents
This is the list of parents.
Definition: ConfigFwd.hpp:28
enabler
Simple empty scoped class.
Definition: TypeTools.hpp:30
std::set< Option * > exclude_options_
Definition: App.hpp:177
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:636
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition: App.hpp:675
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition: App.hpp:2386
bool get_ignore_case() const
Check the status of ignore_case.
Definition: App.hpp:1657
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition: App.hpp:346
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition: App.hpp:239
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition: App.hpp:2843
int get_items_expected_min() const
The total min number of expected string values to be used.
Definition: Option.hpp:739
bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition: App.hpp:544
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition: Option.hpp:306
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
Definition: App.hpp:1460
const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition: App.hpp:1821
Definition: Option.hpp:237
void _process_extras()
Throw an error if anything is left over and should not be.
Definition: App.hpp:2277
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition: App.hpp:167
void _process_callbacks()
Process callbacks. Runs on all subcommands.
Definition: App.hpp:2072
std::vector< App * > get_subcommands() const
Definition: App.hpp:1347
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type)
Definition: App.hpp:2683
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
Definition: App.hpp:477
bool valid_name_string(const std::string &str)
Verify an option/subcommand name.
Definition: StringTools.hpp:230
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition: App.hpp:2530
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:2924
bool get_validate_positionals() const
Get the status of validating positionals.
Definition: App.hpp:1716
Check to see if something is bool (fail check by default)
Definition: TypeTools.hpp:53
Extension of App to better manage groups of options.
Definition: App.hpp:2983
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition: App.hpp:2039
bool valid_later_char(T c)
Verify following characters of an option.
Definition: StringTools.hpp:222
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition: App.hpp:526
Option * set_version_flag(std::string flag_name, std::function< std::string()> vfunc, const std::string &version_help="Display program version information and exit")
Generate the version string through a callback function.
Definition: App.hpp:741
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition: App.hpp:266
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:859
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition: App.hpp:2460
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:3139
std::string name
This is the name.
Definition: ConfigFwd.hpp:31
ConfigBase ConfigTOML
the default Config is the TOML file format
Definition: ConfigFwd.hpp:167
std::vector< std::string > split_up(std::string str, char delimiter='\0')
Definition: StringTools.hpp:346
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:79
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1651
App * callback(std::function< void()> app_callback)
Definition: App.hpp:321
bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition: App.hpp:1669
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition: App.hpp:115
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:949
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition: TypeTools.hpp:862
constexpr enabler dummy
An instance to use in EnableIf.
Definition: TypeTools.hpp:33
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition: App.hpp:788
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:3183
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed...
Definition: App.hpp:999
std::vector< const App * > get_subcommands(const std::function< bool(const App *)> &filter) const
Definition: App.hpp:1351
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:269
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition: App.hpp:1743
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition: App.hpp:141
std::vector< std::string > fnames_
a list of flag names with specified default values;
Definition: Option.hpp:255
Option * add_flag(std::string flag_name, T &flag_description)
Definition: App.hpp:796
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition: App.hpp:86
const Option * get_help_ptr() const
Get a pointer to the help flag. (const)
Definition: App.hpp:1725
bool split_short(const std::string ¤t, std::string &name, std::string &rest)
Definition: Split.hpp:25
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition: Option.hpp:661
Thrown when a required option is missing.
Definition: Error.hpp:219
Option * get_option(std::string option_name)
Get an option by name (non-const version)
Definition: App.hpp:1642
std::string group_
The group membership INHERITABLE.
Definition: App.hpp:248
std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition: App.hpp:1501
path_type check_path(const char *file) noexcept
get the type of the path from a file name
Definition: Validators.hpp:324
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition: Option.hpp:80
bool get_fallthrough() const
Check the status of fallthrough.
Definition: App.hpp:1663
std::vector< Option * > get_options(const std::function< bool(Option *)> filter={})
Non-const version of the above.
Definition: App.hpp:1579
bool get_configurable() const
The status of configurable.
Definition: Option.hpp:133
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition: App.hpp:105
std::size_t count_all() const
Definition: App.hpp:1087
App * enabled_by_default(bool enable=true)
Definition: App.hpp:424
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition: App.hpp:401
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition: App.hpp:223
CLI::App_p get_subcommand_ptr(App *subcom) const
Check to see if a subcommand is part of this command and get a shared_ptr to it.
Definition: App.hpp:1043
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.hpp:875
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition: App.hpp:547
bool split_windows_style(const std::string ¤t, std::string &name, std::string &value)
Definition: Split.hpp:51
Thrown when parsing an INI file and it is missing.
Definition: Error.hpp:189
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition: App.hpp:465
void _process_extras(std::vector< std::string > &args)
Definition: App.hpp:2293
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition: App.hpp:144
Option * get_version_ptr()
Get a pointer to the version option.
Definition: App.hpp:1737
std::unique_ptr< Option > Option_p
Definition: Option.hpp:36
bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition: App.hpp:2517
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition: App.hpp:2317
bool get_disabled() const
Get the status of disabled.
Definition: App.hpp:1702
Option * check(Validator validator, const std::string &validator_name="")
Adds a Validator with a built in type name.
Definition: Option.hpp:456
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise...
Definition: App.hpp:204
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition: StringTools.hpp:336
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition: App.hpp:505
bool fallthrough_
Allow subcommand fallthrough, so that parent commands can collect commands after subcommand. INHERITABLE.
Definition: App.hpp:201
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:63
std::vector< std::string > results_t
Definition: Option.hpp:29
App * description(std::string app_description)
Set the description of the app.
Definition: App.hpp:1556
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition: App.hpp:612
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:3158
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:782
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:138
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:3190
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size() { return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type > { static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count { static constexpr int value{is_mutable_container< T >::value ? expected_max_vector_size :type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min { static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type > { static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type > { static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type > { static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min() { return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min() { return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type > { static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min { static constexpr int value{is_mutable_container< T >::value ?((type_count< T >::value< expected_max_vector_size) ? type_count< T >::value :0) :type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count { static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type > { static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type > { static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type > { static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category :int { char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object { static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type > { static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type > { static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type > { static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type > { static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type > { static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type > { static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1) &&std::is_constructible< T, std::string >::value >::type > { static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type > { static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type > { static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type { using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type > { static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type > { static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type > { static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type > { static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value))>::type > { static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type > { static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name() { return "TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name() { return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name() { return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name() { std::string str=std::string(type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >))+','+tuple_name< T, I+1 >);if(str.back()==',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: TypeTools.hpp:773
Option * run_callback_for_default(bool value=true)
Definition: Option.hpp:448
Usually something like –help-all on command line.
Definition: Error.hpp:169
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition: App.hpp:1108
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition: App.hpp:3008
void clear()
Clear the parsed results (mostly for testing)
Definition: Option.hpp:372
std::vector< std::string > inputs
Listing of inputs.
Definition: ConfigFwd.hpp:34
AppFormatMode
Definition: FormatterFwd.hpp:29
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition: App.hpp:125
CLI::App_p get_subcommand_ptr(int index=0) const
Get an owning pointer to subcommand by index.
Definition: App.hpp:1061
std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition: App.hpp:1858
std::string version() const
Displays a version string.
Definition: App.hpp:1516
void _parse_stream(std::istream &input)
Internal function to parse a stream.
Definition: App.hpp:2363
std::pair< std::string, std::string > split_program_name(std::string commandline)
Definition: Validators.hpp:1093
std::set< Option * > needs_
A list of options that are required with this option.
Definition: Option.hpp:303
void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
Definition: App.hpp:3085
All errors derive from this one.
Definition: Error.hpp:70
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:2874
bool prefix_command_
If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
Definition: App.hpp:93
missing_t missing_
Definition: App.hpp:164
App * allow_windows_style_options(bool value=true)
Definition: App.hpp:493
void _process_config_file()
Read and process a configuration file (main app only)
Definition: App.hpp:2006
std::string & trim(std::string &str)
Trim whitespace from string.
Definition: StringTools.hpp:138
void _configure()
Definition: App.hpp:1918
std::string remove_underscore(std::string str)
remove underscores from a string
Definition: StringTools.hpp:267
bool required_
True if this is a required option.
Definition: Option.hpp:56
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:3000
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition: Option.hpp:252
App * add_subcommand(CLI::App_p subcom)
Add a previously created app as a subcommand.
Definition: App.hpp:985
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:1562
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:395
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer) ...
Definition: App.hpp:261
std::set< App * > need_subcommands_
Definition: App.hpp:181
Option * description(std::string option_description)
Set the description.
Definition: Option.hpp:762
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition: App.hpp:80
Definition: Option.hpp:200
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTools.hpp:41
const Option * get_option_no_throw(std::string option_name) const noexcept
Get an option by name (noexcept const version)
Definition: App.hpp:1614
App * alias(std::string app_name)
Set an alias for the app.
Definition: App.hpp:370
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition: App.hpp:532
The normal, detailed help.
bool remove_needs(App *app)
Removes a subcommand from the needs list of this subcommand.
Definition: App.hpp:1470
const Option * get_option(std::string option_name) const
Get an option by name.
Definition: App.hpp:1633
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:1979
int get_type_size_min() const
The minimum number of arguments the option expects.
Definition: Option.hpp:687
void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
Definition: App.hpp:3037
int get_type_size_max() const
The maximum number of arguments the option expects.
Definition: Option.hpp:689
bool remove_excludes(App *app)
Removes a subcommand from the excludes list of this subcommand.
Definition: App.hpp:1448
Option * get_help_ptr()
Get a pointer to the help flag.
Definition: App.hpp:1722
bool silent_
Definition: App.hpp:227
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:899
Option * type_size(int option_type_size)
Set a custom option size.
Definition: Option.hpp:1088
App & operator=(const App &)=delete
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
Definition: App.hpp:435
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:1309
void remove_default_flag_values(std::string &flags)
Definition: StringTools.hpp:290
std::size_t count() const
Definition: App.hpp:1083
config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition: App.hpp:1719
App * footer(std::string footer_string)
Set footer.
Definition: App.hpp:1484
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition: App.hpp:454
const std::string & get_name() const
Get the name of the current app.
Definition: App.hpp:1749
App * require_subcommand(int value)
Definition: App.hpp:1117
std::size_t escape_detect(std::string &str, std::size_t offset)
Definition: StringTools.hpp:402
Option * config_ptr_
Pointer to the config option.
Definition: App.hpp:258
void parse(int argc, const char *const *argv)
Definition: App.hpp:1207
std::string fullname() const
The list of parents and name joined by ".".
Definition: ConfigFwd.hpp:37
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition: App.hpp:2309
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition: StringTools.hpp:259
void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
Definition: App.hpp:3016
App * final_callback(std::function< void()> app_callback)
Definition: App.hpp:332
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:1851
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition: App.hpp:198
This will only trigger for actual void type.
Definition: TypeTools.hpp:390
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition: Option.hpp:186
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
Definition: App.hpp:352
App * get_subcommand(int index=0) const
Get a pointer to subcommand by index.
Definition: App.hpp:1033
void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
Definition: App.hpp:3058
Some validators that are provided.
Definition: Validators.hpp:77
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition: App.hpp:112
bool get_immediate_callback() const
Get the status of disabled.
Definition: App.hpp:1708
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition: App.hpp:966
take only the last Expected number of arguments
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE...
Definition: App.hpp:236
App * get_subcommand(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
Definition: App.hpp:1026
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:1053
const std::string & get_group() const
Get the group of this option.
Definition: Option.hpp:121
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:567
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:654
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition: App.hpp:1385
bool get_enabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1714
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition: App.hpp:1403
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition: App.hpp:448
bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition: App.hpp:1660
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed...
Definition: App.hpp:926
const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition: App.hpp:1752
T as() const
Return the results as the specified type.
Definition: Option.hpp:1062
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition: App.hpp:499
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Definition: App.hpp:511
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition: Option.hpp:1082
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:842
bool check_name(std::string name_to_check) const
Check the name, case insensitive and underscore insensitive if set.
Definition: App.hpp:1778
const Option * get_config_ptr() const
Get a pointer to the config option. (const)
Definition: App.hpp:1734
const std::string & get_group() const
Get the group of this subcommand.
Definition: App.hpp:1675
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition: App.hpp:3196
-v or –version on command line
Definition: Error.hpp:176
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition: App.hpp:2122
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:1965
App * needs(Option *opt)
Definition: App.hpp:1418
App * require_option(int value)
Definition: App.hpp:1146
Holds values to load into Options.
Definition: ConfigFwd.hpp:26
config_extras_mode allow_config_extras_
Definition: App.hpp:90
the callback has been executed
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition: App.hpp:170
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition: App.hpp:159
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition: App.hpp:3002
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer) ...
Definition: App.hpp:150
bool get_allow_extra_args() const
Get the current value of allow extra args.
Definition: Option.hpp:429
std::function< bool(const results_t &)> callback_t
callback function definition
Definition: Option.hpp:31
startup_mode
Definition: App.hpp:214
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition: App.hpp:1394
bool ignore_case_
If true, the program name is not case sensitive INHERITABLE.
Definition: App.hpp:195
bool get_disabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1711
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition: App.hpp:1489
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition: App.hpp:828
bool get_positional() const
True if the argument can be given directly.
Definition: Option.hpp:750
void parse(std::vector< std::string > &&args)
The real work is done here. Expects a reversed vector.
Definition: App.hpp:1274
void _validate() const
Definition: App.hpp:1879
bool get_configurable() const
Check the status of the allow windows style options.
Definition: App.hpp:1672
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app...
Definition: App.hpp:99
Creates a command line program, with very few defaults.
Definition: App.hpp:69
App * group(std::string group_name)
Changes the group membership.
Definition: App.hpp:1102
bool get_required() const
Get the status of required.
Definition: App.hpp:1699
std::vector< App * > get_subcommands(const std::function< bool(App *)> &filter)
Definition: App.hpp:1369
just get all the passed argument regardless
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
Definition: App.hpp:1595
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:688
bool valid_first_char(T c)
Definition: StringTools.hpp:219
std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition: App.hpp:1343
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition: App.hpp:153
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE ...
Definition: App.hpp:220
This converter works with INI/TOML files; to write INI files use ConfigINI.
Definition: ConfigFwd.hpp:78
App * require_subcommand(std::size_t min, std::size_t max)
Definition: App.hpp:1130
bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition: App.hpp:1666
std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition: App.hpp:1681
void parse_from_stream(std::istream &input)
Definition: App.hpp:1293
bool immediate_callback_
Definition: App.hpp:109
int get_exit_code() const
Definition: Error.hpp:75
bool has_default_flag_values(const std::string &flags)
check if the flag definitions has possible false flags
Definition: StringTools.hpp:286
-h or –help on command line
Definition: Error.hpp:163
Thrown when counting a non-existent option.
Definition: Error.hpp:340
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition: App.hpp:173
std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition: App.hpp:1537
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:2862
std::enable_if< std::is_integral< T >::value, bool >::type checked_multiply(T &a, T b)
Performs a *= b; if it doesn't cause integer overflow. Returns false otherwise.
Definition: Validators.hpp:645
App * parse_complete_callback(std::function< void()> pc_callback)
Definition: App.hpp:339
Option * expected(int value)
Set the number of expected arguments.
Definition: Option.hpp:382
const results_t & results() const
Get the current complete results set.
Definition: Option.hpp:1009
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition: StringTools.hpp:242
App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition: App.hpp:2631
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition: App.hpp:230
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value) ...
Definition: Option.hpp:1149
std::shared_ptr< App > App_p
Definition: App.hpp:62
Option * add_result(std::string s)
Puts a result at the end.
Definition: Option.hpp:986
std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition: App.hpp:1761
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable ...
Definition: App.hpp:212
App * get_subcommand(const App *subcom) const
Definition: App.hpp:1016
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:2992
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:413
void parse(std::string commandline, bool program_name_included=false)
Definition: App.hpp:1225
constexpr int expected_max_vector_size
Definition: StringTools.hpp:43
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition: App.hpp:1807
std::string get_flag_value(const std::string &name, std::string input_value) const
Definition: Option.hpp:942
void _process()
Process callbacks and such.
Definition: App.hpp:2251
void run_callback()
Process the callback.
Definition: Option.hpp:842
App * fallthrough(bool value=true)
Definition: App.hpp:1167
Option_group(std::string group_description, std::string group_name, App *parent)
Definition: App.hpp:2985
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition: App.hpp:242
bool got_subcommand(std::string subcommand_name) const
Check with name instead of pointer to see if subcommand was selected.
Definition: App.hpp:1391
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition: App.hpp:1728
void _parse_config(const std::vector< ConfigItem > &args)
Definition: App.hpp:2378
virtual void pre_callback()
Definition: App.hpp:1183
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:705
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
Definition: App.hpp:2099
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition: App.hpp:118