15#include "../Encoding.hpp"
30CLI11_INLINE
App::App(std::string app_description, std::string app_name,
App *parent)
31 : name_(std::move(app_name)), description_(std::move(app_description)), parent_(parent) {
69 normalized_argv_ = detail::compute_win32_argv();
71 if(!normalized_argv_view_.empty()) {
72 normalized_argv_view_.clear();
75 normalized_argv_view_.reserve(normalized_argv_.size());
76 for(
auto &arg : normalized_argv_) {
78 normalized_argv_view_.push_back(
const_cast<char *
>(arg.data()));
81 return normalized_argv_view_.data();
90 std::string oname =
name_;
105 if(app_name.empty() || !detail::valid_alias_name_string(app_name)) {
113 throw(
OptionAlreadyAdded(
"alias already matches an existing subcommand: " + app_name));
141 throw OptionAlreadyAdded(
"ignore case would cause subcommand name conflicts: " + match);
155 throw OptionAlreadyAdded(
"ignore underscore would cause subcommand name conflicts: " + match);
163 callback_t option_callback,
164 std::string option_description,
166 std::function<std::string()> func) {
171 std::find_if(std::begin(
options_), std::end(
options_), [&myopt](
const Option_p &v) {
return *v == myopt; });
173 const auto &matchname = (*res)->matching_name(myopt);
177 const App *top_level_parent =
this;
178 while(top_level_parent->
name_.empty() && top_level_parent->
parent_ !=
nullptr) {
179 top_level_parent = top_level_parent->
parent_;
182 if(myopt.lnames_.empty() && myopt.snames_.empty()) {
185 std::string test_name =
"--" + myopt.get_single_name();
186 if(test_name.size() == 3) {
187 test_name.erase(0, 1);
191 if(op !=
nullptr && op->get_configurable()) {
192 throw(
OptionAlreadyAdded(
"added option positional name matches existing option: " + test_name));
197 if(op !=
nullptr && op->lnames_.empty() && op->snames_.empty()) {
198 throw(
OptionAlreadyAdded(
"unable to disambiguate with existing option: " + test_name));
200 }
else if(top_level_parent !=
this) {
201 for(
auto &ln : myopt.lnames_) {
203 if(op !=
nullptr && op->get_configurable()) {
207 if(op !=
nullptr && op->get_configurable()) {
212 if(op !=
nullptr && op->get_configurable()) {
217 for(
auto &sn : myopt.snames_) {
219 if(op !=
nullptr && op->get_configurable()) {
223 if(op !=
nullptr && op->get_configurable()) {
227 if(op !=
nullptr && op->get_configurable()) {
234 for(
auto &sname : myopt.snames_) {
235 if(sname.length() > 1) {
236 std::string test_name;
237 test_name.push_back(
'-');
238 test_name.push_back(sname.front());
241 throw(
OptionAlreadyAdded(
"added option interferes with existing short option: " + sname));
246 for(
const auto &osn : opt->snames_) {
248 std::string test_name;
249 test_name.push_back(osn.front());
250 if(myopt.check_sname(test_name)) {
251 throw(
OptionAlreadyAdded(
"added option interferes with existing non standard option: " + osn));
262 option->default_function(func);
266 option->capture_default_str();
272 if(!defaulted && option->get_always_capture_default())
273 option->capture_default_str();
286 if(!flag_name.empty()) {
302 if(!help_name.empty()) {
319 if(!flag_name.empty()) {
321 flag_name, [versionString]() {
throw(
CLI::CallForVersion(versionString, 0)); }, version_help);
336 if(!flag_name.empty()) {
345CLI11_INLINE
Option *App::_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description) {
347 if(detail::has_default_flag_values(flag_name)) {
349 auto flag_defaults = detail::get_default_flag_values(flag_name);
350 detail::remove_default_flag_values(flag_name);
351 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
352 for(
const auto &fname : flag_defaults)
353 opt->
fnames_.push_back(fname.first);
356 opt =
add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
360 auto pos_name = opt->
get_name(
true);
362 throw IncorrectConstruction::PositionalFlag(pos_name);
371 std::function<
void(
void)> function,
372 std::string flag_description) {
374 CLI::callback_t fun = [function](
const CLI::results_t &res) {
375 using CLI::detail::lexical_cast;
377 auto result = lexical_cast(res[0], trigger);
378 if(result && trigger) {
383 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
388 std::function<
void(std::int64_t)> function,
389 std::string flag_description) {
391 CLI::callback_t fun = [function](
const CLI::results_t &res) {
392 using CLI::detail::lexical_cast;
393 std::int64_t flag_count{0};
394 lexical_cast(res[0], flag_count);
395 function(flag_count);
398 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
403 std::string default_filename,
404 const std::string &help_message,
405 bool config_required) {
414 if(!option_name.empty()) {
416 if(config_required) {
419 if(!default_filename.empty()) {
434 op->remove_needs(opt);
435 op->remove_excludes(opt);
446 std::find_if(std::begin(
options_), std::end(
options_), [opt](
const Option_p &v) {
return v.get() == opt; });
447 if(iterator != std::end(
options_)) {
455 if(!subcommand_name.empty() && !detail::valid_name_string(subcommand_name)) {
456 if(!detail::valid_first_char(subcommand_name[0])) {
458 "Subcommand name starts with invalid character, '!' and '-' and control characters");
460 for(
auto c : subcommand_name) {
461 if(!detail::valid_later_char(c)) {
463 "'), all characters are allowed except"
464 "'=',':','{','}', ' ', and control characters");
468 CLI::App_p subcom = std::shared_ptr<App>(
new App(std::move(subcommand_description), subcommand_name,
this));
478 throw(
OptionAlreadyAdded(
"subcommand name or alias matches existing subcommand: " + mstrg));
480 subcom->parent_ =
this;
488 sub->remove_excludes(subcom);
489 sub->remove_needs(subcom);
492 auto iterator = std::find_if(
502 if(subcom ==
nullptr)
505 if(subcomptr.get() == subcom)
506 return subcomptr.get();
518 return _find_subcommand(subcom,
false,
false);
523 auto uindex =
static_cast<unsigned>(index);
531 if(subcom ==
nullptr)
534 if(subcomptr.get() == subcom)
541 if(subcomptr->check_name(subcom))
548 auto uindex =
static_cast<unsigned>(index);
557 if(app->name_.empty() && app->group_ == group_name) {
570 cnt += sub->count_all();
586 for(
const Option_p &opt :
options_) {
594CLI11_INLINE
void App::parse(
int argc,
const char *
const *argv) { parse_char_t(argc, argv); }
595CLI11_INLINE
void App::parse(
int argc,
const wchar_t *
const *argv) { parse_char_t(argc, argv); }
600CLI11_INLINE
const char *maybe_narrow(
const char *str) {
return str; }
601CLI11_INLINE std::string maybe_narrow(
const wchar_t *str) {
return narrow(str); }
605template <
class CharT> CLI11_INLINE
void App::parse_char_t(
int argc,
const CharT *
const *argv) {
609 name_ = detail::maybe_narrow(argv[0]);
612 std::vector<std::string> args;
613 args.reserve(
static_cast<std::size_t
>(argc) - 1U);
614 for(
auto i =
static_cast<std::size_t
>(argc) - 1U; i > 0U; --i)
615 args.emplace_back(detail::maybe_narrow(argv[i]));
617 parse(std::move(args));
620CLI11_INLINE
void App::parse(std::string commandline,
bool program_name_included) {
622 if(program_name_included) {
623 auto nstr = detail::split_program_name(commandline);
628 commandline = std::move(nstr.second);
630 detail::trim(commandline);
633 if(!commandline.empty()) {
634 commandline = detail::find_and_modify(commandline,
"=", detail::escape_detect);
636 commandline = detail::find_and_modify(commandline,
":", detail::escape_detect);
639 auto args = detail::split_up(std::move(commandline));
641 args.erase(std::remove(args.begin(), args.end(), std::string{}), args.end());
643 detail::remove_quotes(args);
644 }
catch(
const std::invalid_argument &arg) {
647 std::reverse(args.begin(), args.end());
648 parse(std::move(args));
651CLI11_INLINE
void App::parse(std::wstring commandline,
bool program_name_included) {
652 parse(narrow(commandline), program_name_included);
655CLI11_INLINE
void App::parse(std::vector<std::string> &args) {
674CLI11_INLINE
void App::parse(std::vector<std::string> &&args) {
693CLI11_INLINE
void App::parse_from_stream(std::istream &input) {
704CLI11_INLINE
int App::exit(
const Error &e, std::ostream &out, std::ostream &err)
const {
707 if(e.get_name() ==
"RuntimeError")
708 return e.get_exit_code();
710 if(e.get_name() ==
"CallForHelp") {
712 return e.get_exit_code();
715 if(e.get_name() ==
"CallForAllHelp") {
716 out <<
help(
"", AppFormatMode::All);
717 return e.get_exit_code();
720 if(e.get_name() ==
"CallForVersion") {
721 out << e.what() <<
'\n';
722 return e.get_exit_code();
725 if(e.get_exit_code() !=
static_cast<int>(ExitCodes::Success)) {
730 return e.get_exit_code();
739 subcomms.erase(std::remove_if(std::begin(subcomms),
741 [&filter](
const App *app) {
return !filter(app); }),
755 std::remove_if(std::begin(subcomms), std::end(subcomms), [&filter](
App *app) {
return !filter(app); }),
776 auto *other_app = *iterator;
778 other_app->remove_excludes(
this);
800CLI11_NODISCARD CLI11_INLINE std::string
App::help(std::string prev, AppFormatMode mode)
const {
808 if(!selected_subcommands.empty()) {
809 return selected_subcommands.back()->help(prev, mode);
811 return formatter_->make_help(
this, prev, mode);
833 std::vector<const Option *> options(
options_.size());
835 std::begin(
options_), std::end(
options_), std::begin(options), [](
const Option_p &val) {
return val.get(); });
838 options.erase(std::remove_if(std::begin(options),
840 [&filter](
const Option *opt) {
return !filter(opt); }),
845 const App *subc = subcp.get();
847 std::vector<const Option *> subcopts = subc->
get_options(filter);
848 options.insert(options.end(), subcopts.begin(), subcopts.end());
855 std::vector<Option *> options(
options_.size());
857 std::begin(
options_), std::end(
options_), std::begin(options), [](
const Option_p &val) {
return val.get(); });
861 std::remove_if(std::begin(options), std::end(options), [&filter](
Option *opt) {
return !filter(opt); }),
866 if(subc->get_name().empty() || (!subc->get_group().empty() && subc->get_group().front() ==
'+')) {
867 auto subcopts = subc->get_options(filter);
868 options.insert(options.end(), subcopts.begin(), subcopts.end());
875 for(Option_p &opt : options_) {
880 for(
auto &subc : subcommands_) {
882 if(subc->get_name().empty()) {
883 auto *opt = subc->get_option_no_throw(option_name);
893 for(
const Option_p &opt : options_) {
898 for(
const auto &subc : subcommands_) {
900 if(subc->get_name().empty()) {
901 auto *opt = subc->get_option_no_throw(option_name);
912 return std::string(
"[Option Group: ") +
get_group() +
"]";
914 if(
aliases_.empty() || !with_aliases) {
917 std::string dispname =
name_;
918 for(
const auto &lalias :
aliases_) {
919 dispname.push_back(
',');
920 dispname.push_back(
' ');
921 dispname.append(lalias);
928 return (result != NameMatch::none);
932 std::string local_name =
name_;
934 local_name = detail::remove_underscore(
name_);
935 name_to_check = detail::remove_underscore(name_to_check);
938 local_name = detail::to_lower(
name_);
939 name_to_check = detail::to_lower(name_to_check);
942 if(local_name == name_to_check) {
943 return App::NameMatch::exact;
946 if(local_name.compare(0, name_to_check.size(), name_to_check) == 0) {
947 return App::NameMatch::prefix;
952 les = detail::remove_underscore(les);
955 les = detail::to_lower(les);
957 if(les == name_to_check) {
958 return App::NameMatch::exact;
961 if(les.compare(0, name_to_check.size(), name_to_check) == 0) {
962 return App::NameMatch::prefix;
966 return App::NameMatch::none;
970 std::vector<std::string> groups;
972 for(
const Option_p &opt :
options_) {
974 if(std::find(groups.begin(), groups.end(), opt->
get_group()) == groups.end()) {
982CLI11_NODISCARD CLI11_INLINE std::vector<std::string>
App::remaining(
bool recurse)
const {
983 std::vector<std::string> miss_list;
984 for(
const std::pair<detail::Classifier, std::string> &miss :
missing_) {
985 miss_list.push_back(std::get<1>(miss));
991 if(sub->name_.empty() && !sub->missing_.empty()) {
992 for(
const std::pair<detail::Classifier, std::string> &miss : sub->missing_) {
993 miss_list.push_back(std::get<1>(miss));
1001 std::vector<std::string> output = sub->remaining(recurse);
1002 std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list));
1009 std::vector<std::string> miss_list =
remaining(recurse);
1010 std::reverse(std::begin(miss_list), std::end(miss_list));
1015 auto remaining_options =
static_cast<std::size_t
>(std::count_if(
1016 std::begin(
missing_), std::end(
missing_), [](
const std::pair<detail::Classifier, std::string> &val) {
1017 return val.first != detail::Classifier::POSITIONAL_MARK;
1022 remaining_options += sub->remaining_size(recurse);
1025 return remaining_options;
1030 auto pcount = std::count_if(std::begin(
options_), std::end(
options_), [](
const Option_p &opt) {
1031 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional();
1034 auto pcount_req = std::count_if(std::begin(
options_), std::end(
options_), [](
const Option_p &opt) {
1035 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional() &&
1036 opt->get_required();
1038 if(pcount - pcount_req > 1) {
1043 std::size_t nameless_subs{0};
1046 if(app->get_name().empty())
1053 throw(
InvalidError(
"Required min options greater than required max options", ExitCodes::InvalidError));
1058 InvalidError(
"Required min options greater than number of available options", ExitCodes::InvalidError));
1070 if(app->has_automatic_name_) {
1073 if(app->name_.empty()) {
1074 app->fallthrough_ =
false;
1075 app->prefix_command_ =
false;
1078 app->parent_ =
this;
1091 if(subc->parent_ ==
this) {
1092 subc->run_callback(
true, suppress_final_callback);
1097 if(subc->name_.empty() && subc->count_all() > 0) {
1098 subc->run_callback(
true, suppress_final_callback);
1117 if(com !=
nullptr) {
1127CLI11_NODISCARD CLI11_INLINE detail::Classifier
App::_recognize(
const std::string ¤t,
1128 bool ignore_used_subcommands)
const {
1129 std::string dummy1, dummy2;
1132 return detail::Classifier::POSITIONAL_MARK;
1134 return detail::Classifier::SUBCOMMAND;
1135 if(detail::split_long(current, dummy1, dummy2))
1136 return detail::Classifier::LONG;
1137 if(detail::split_short(current, dummy1, dummy2)) {
1138 if((dummy1[0] >=
'0' && dummy1[0] <=
'9') ||
1139 (dummy1[0] ==
'.' && !dummy2.empty() && (dummy2[0] >=
'0' && dummy2[0] <=
'9'))) {
1142 return detail::Classifier::NONE;
1145 return detail::Classifier::SHORT;
1148 return detail::Classifier::WINDOWS_STYLE;
1149 if((current ==
"++") && !
name_.empty() &&
parent_ !=
nullptr)
1150 return detail::Classifier::SUBCOMMAND_TERMINATOR;
1151 auto dotloc = current.find_first_of(
'.');
1152 if(dotloc != std::string::npos) {
1153 auto *cm =
_find_subcommand(current.substr(0, dotloc),
true, ignore_used_subcommands);
1155 auto res = cm->_recognize(current.substr(dotloc + 1), ignore_used_subcommands);
1156 if(res == detail::Classifier::SUBCOMMAND) {
1161 return detail::Classifier::NONE;
1165 auto path_result = detail::check_path(config_file.c_str());
1166 if(path_result == detail::path_type::file) {
1177 }
else if(throw_error) {
1178 throw FileError::Missing(config_file);
1190 if(!ename_string.empty()) {
1196 auto config_files =
config_ptr_->
as<std::vector<std::string>>();
1197 bool files_used{file_given};
1198 if(config_files.empty() || config_files.front().empty()) {
1199 if(config_required) {
1200 throw FileError(
"config file is required but none was given");
1204 for(
const auto &config_file : config_files) {
1221 for(
const Option_p &opt :
options_) {
1223 std::string ename_string = detail::get_environment_value(opt->
envname_);
1224 if(!ename_string.empty()) {
1225 std::string result = ename_string;
1226 result = opt->_validate(result, 0);
1227 if(result.empty()) {
1235 if(sub->get_name().empty() || (sub->count_all() > 0 && !sub->parse_complete_callback_)) {
1237 sub->_process_env();
1246 if(sub->get_name().empty() && sub->parse_complete_callback_) {
1247 if(sub->count_all() > 0) {
1248 sub->_process_callbacks(priority);
1249 if(priority == CallbackPriority::Normal) {
1251 sub->run_callback();
1257 for(
const Option_p &opt :
options_) {
1265 if(!sub->parse_complete_callback_) {
1266 sub->_process_callbacks(priority);
1276 trigger_help =
true;
1278 trigger_all_help =
true;
1283 sub->_process_help_flags(priority, trigger_help, trigger_all_help);
1286 }
else if(trigger_all_help) {
1288 }
else if(trigger_help) {
1295 bool excluded{
false};
1296 std::string excluder;
1298 if(opt->
count() > 0) {
1304 if(subc->count_all() > 0) {
1306 excluder = subc->get_display_name();
1318 bool missing_needed{
false};
1319 std::string missing_need;
1321 if(opt->
count() == 0) {
1322 missing_needed =
true;
1327 if(subc->count_all() == 0) {
1328 missing_needed =
true;
1329 missing_need = subc->get_display_name();
1332 if(missing_needed) {
1340 std::size_t used_options = 0;
1341 for(
const Option_p &opt :
options_) {
1343 if(opt->
count() != 0) {
1352 if(opt->
count() > 0 && opt_req->
count() == 0)
1373 if(sub->name_.empty() && sub->count_all() > 0) {
1379 auto option_list = detail::join(
options_, [
this](
const Option_p &ptr) {
1381 return std::string{};
1383 return ptr->get_name(
false,
true);
1387 if(!subc_list.empty()) {
1388 option_list +=
"," + detail::join(subc_list, [](
const App *app) {
return app->
get_display_name(); });
1397 if(sub->name_.empty() && sub->required_ ==
false) {
1398 if(sub->count_all() == 0) {
1411 if(sub->count() > 0 || sub->name_.empty()) {
1412 sub->_process_requirements();
1415 if(sub->required_ && sub->count_all() == 0) {
1428 std::exception_ptr config_exception;
1437 config_exception = std::current_exception();
1451 if(config_exception) {
1452 std::rethrow_exception(config_exception);
1463 if(num_left_over > 0) {
1469 if(sub->count() > 0)
1470 sub->_process_extras();
1477 if(num_left_over > 0) {
1484 if(sub->count() > 0)
1485 sub->_process_extras(args);
1492 if(sub->get_name().empty())
1493 sub->increment_parsed();
1500 bool positional_only =
false;
1502 while(!args.empty()) {
1540 bool positional_only =
false;
1542 while(!args.empty()) {
1565 throw ConfigError::Extras(item.fullname());
1571 if(item.
inputs.size() <= 1) {
1574 bool converted{
false};
1576 auto val = detail::to_flag_value(res);
1601 throw ConversionError::TooManyInputsFlag(item.
fullname());
1605 for(
const auto &res : inputs) {
1606 bool valid_value{
false};
1608 if(res ==
"true" || res ==
"false" || res ==
"1" || res ==
"0") {
1613 if(valid_res.second == res) {
1633 if(level < item.
parents.size()) {
1635 return (subcom !=
nullptr) ? subcom->_parse_single_config(item, level + 1) :
false;
1638 if(item.
name ==
"++") {
1649 if(item.
name ==
"--") {
1666 if(item.
name.size() == 1) {
1673 if(item.
name.size() == 1) {
1675 if(testop !=
nullptr && testop->get_configurable()) {
1681 std::string iname = item.
name;
1686 if(!options.empty()) {
1695 for(
const auto &input : item.
inputs) {
1696 missing_.emplace_back(detail::Classifier::NONE, input);
1706 throw ConfigError::NotConfigurable(item.
fullname());
1709 std::vector<std::string> buffer;
1710 bool useBuffer{
false};
1714 buffer.erase(std::remove(buffer.begin(), buffer.end(),
"%%"), buffer.end());
1718 const std::vector<std::string> &inputs = (useBuffer) ? buffer : item.
inputs;
1733 detail::Classifier classifier = positional_only ? detail::Classifier::NONE :
_recognize(args.back());
1734 switch(classifier) {
1735 case detail::Classifier::POSITIONAL_MARK:
1737 positional_only =
true;
1744 case detail::Classifier::SUBCOMMAND_TERMINATOR:
1749 case detail::Classifier::SUBCOMMAND:
1752 case detail::Classifier::LONG:
1753 case detail::Classifier::SHORT:
1754 case detail::Classifier::WINDOWS_STYLE:
1756 retval =
_parse_arg(args, classifier,
false);
1758 case detail::Classifier::NONE:
1762 positional_only =
true;
1767 throw HorribleError(
"unrecognized classifier (you should not see this!)");
1774 std::size_t retval = 0;
1775 for(
const Option_p &opt :
options_) {
1786 for(
const Option_p &opt :
options_) {
1797 const std::string &positional = args.back();
1802 auto arg_rem = args.size();
1804 if(arg_rem <= remreq) {
1805 for(
const Option_p &opt :
options_) {
1809 std::string pos = positional;
1810 pos = opt->_validate(pos, 0);
1822 if(posOpt ==
nullptr) {
1823 for(
const Option_p &opt :
options_) {
1828 std::string pos = positional;
1829 pos = opt->_validate(pos, 0);
1839 if(posOpt !=
nullptr) {
1841 if(posOpt->get_inject_separator()) {
1842 if(!posOpt->results().empty() && !posOpt->results().back().empty()) {
1843 posOpt->add_result(std::string{});
1848 prev = posOpt->results();
1851 if(posOpt->get_expected_min() == 0) {
1853 item.
name = posOpt->pname_;
1854 item.
inputs.push_back(positional);
1858 posOpt->add_result(positional);
1861 if(posOpt->get_trigger_on_parse()) {
1862 if(!posOpt->empty()) {
1863 posOpt->run_callback();
1866 posOpt->add_result(prev);
1876 if((subc->name_.empty()) && (!subc->disabled_)) {
1877 if(subc->_parse_positional(args,
false)) {
1878 if(!subc->pre_parse_called_) {
1879 subc->_trigger_pre_parse(args.size());
1892 if(haltOnSubcommand) {
1904 if(com !=
nullptr && (com->parent_->require_subcommand_max_ == 0 ||
1905 com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) {
1910 std::vector<std::string> rargs;
1911 rargs.resize(args.size());
1912 std::reverse_copy(args.begin(), args.end(), rargs.begin());
1923 while(!args.empty()) {
1932CLI11_NODISCARD CLI11_INLINE
App *
1935 for(
const App_p &com : subcommands_) {
1936 if(com->disabled_ && ignore_disabled)
1938 if(com->get_name().empty()) {
1939 auto *subc = com->_find_subcommand(subc_name, ignore_disabled, ignore_used);
1940 if(subc !=
nullptr) {
1941 if(bcom !=
nullptr) {
1945 if(!allow_prefix_matching_) {
1950 auto res = com->check_name_detail(subc_name);
1951 if(res != NameMatch::none) {
1952 if((!*com) || !ignore_used) {
1953 if(res == NameMatch::exact) {
1956 if(bcom !=
nullptr) {
1960 if(!allow_prefix_matching_) {
1975 if(com ==
nullptr) {
1977 auto dotloc = args.back().find_first_of(
'.');
1978 if(dotloc != std::string::npos) {
1980 if(com !=
nullptr) {
1981 args.back() = args.back().substr(dotloc + 1);
1982 args.push_back(com->get_display_name());
1986 if(com !=
nullptr) {
1992 auto *parent_app = com->parent_;
1993 while(parent_app !=
this) {
1994 parent_app->_trigger_pre_parse(args.size());
1996 parent_app->parsed_subcommands_.push_back(com);
1998 parent_app = parent_app->parent_;
2004 throw HorribleError(
"Subcommand " + args.back() +
" missing");
2009App::_parse_arg(std::vector<std::string> &args, detail::Classifier current_type,
bool local_processing_only) {
2011 std::string current = args.back();
2013 std::string arg_name;
2017 switch(current_type) {
2018 case detail::Classifier::LONG:
2019 if(!detail::split_long(current, arg_name, value))
2020 throw HorribleError(
"Long parsed but missing (you should not see this):" + args.back());
2022 case detail::Classifier::SHORT:
2023 if(!detail::split_short(current, arg_name, rest))
2024 throw HorribleError(
"Short parsed but missing! You should not see this");
2026 case detail::Classifier::WINDOWS_STYLE:
2027 if(!detail::split_windows_style(current, arg_name, value))
2028 throw HorribleError(
"windows option parsed but missing! You should not see this");
2030 case detail::Classifier::SUBCOMMAND:
2031 case detail::Classifier::SUBCOMMAND_TERMINATOR:
2032 case detail::Classifier::POSITIONAL_MARK:
2033 case detail::Classifier::NONE:
2035 throw HorribleError(
"parsing got called with invalid option! You should not see this");
2038 auto op_ptr = std::find_if(std::begin(
options_), std::end(
options_), [arg_name, current_type](
const Option_p &opt) {
2039 if(current_type == detail::Classifier::LONG)
2040 return opt->check_lname(arg_name);
2041 if(current_type == detail::Classifier::SHORT)
2042 return opt->check_sname(arg_name);
2044 return opt->check_lname(arg_name) || opt->check_sname(arg_name);
2048 while(op_ptr == std::end(
options_)) {
2051 if(subc->name_.empty() && !subc->disabled_) {
2052 if(subc->_parse_arg(args, current_type, local_processing_only)) {
2053 if(!subc->pre_parse_called_) {
2054 subc->_trigger_pre_parse(args.size());
2061 std::string narg_name;
2063 detail::split_long(std::string{
'-'} + current, narg_name, nvalue);
2064 op_ptr = std::find_if(std::begin(
options_), std::end(
options_), [narg_name](
const Option_p &opt) {
2065 return opt->check_sname(narg_name);
2068 arg_name = narg_name;
2081 auto dotloc = arg_name.find_first_of(
'.', 1);
2082 if(dotloc != std::string::npos && dotloc < arg_name.size() - 1) {
2085 if(sub !=
nullptr) {
2086 std::string v = args.back();
2088 arg_name = arg_name.substr(dotloc + 1);
2089 if(arg_name.size() > 1) {
2090 args.push_back(std::string(
"--") + v.substr(dotloc + 3));
2091 current_type = detail::Classifier::LONG;
2093 auto nval = v.substr(dotloc + 2);
2095 if(nval.size() > 2) {
2097 args.push_back(nval.substr(3));
2100 args.push_back(nval);
2101 current_type = detail::Classifier::SHORT;
2103 std::string dummy1, dummy2;
2105 if((current_type == detail::Classifier::SHORT && detail::valid_first_char(args.back()[1])) ||
2106 detail::split_long(args.back(), dummy1, dummy2)) {
2107 val = sub->_parse_arg(args, current_type,
true);
2118 if(sub->parse_complete_callback_) {
2119 sub->_process_callbacks(CallbackPriority::FirstPreHelp);
2120 sub->_process_help_flags(CallbackPriority::First);
2121 sub->_process_callbacks(CallbackPriority::First);
2122 sub->_process_env();
2123 sub->_process_callbacks(CallbackPriority::PreRequirementsCheckPreHelp);
2124 sub->_process_help_flags(CallbackPriority::PreRequirementsCheck);
2125 sub->_process_callbacks(CallbackPriority::PreRequirementsCheck);
2126 sub->_process_requirements();
2127 sub->_process_callbacks(CallbackPriority::NormalPreHelp);
2128 sub->_process_help_flags(CallbackPriority::Normal);
2129 sub->_process_callbacks(CallbackPriority::Normal);
2130 sub->_process_callbacks(CallbackPriority::LastPreHelp);
2131 sub->_process_help_flags(CallbackPriority::Last);
2132 sub->_process_callbacks(CallbackPriority::Last);
2133 sub->run_callback(
false,
true);
2141 if(local_processing_only) {
2157 Option_p &op = *op_ptr;
2159 if(op->get_inject_separator()) {
2160 if(!op->results().empty() && !op->results().back().empty()) {
2161 op->add_result(std::string{});
2167 int min_num = (std::min)(op->get_type_size_min(), op->get_items_expected_min());
2168 int max_num = op->get_items_expected_max();
2171 if(max_num >= detail::expected_max_vector_size / 16 && !op->get_allow_extra_args()) {
2172 auto tmax = op->get_type_size_max();
2173 max_num = detail::checked_multiply(tmax, op->get_expected_min()) ? tmax : detail::expected_max_vector_size;
2177 int result_count = 0;
2180 auto res = op->get_flag_value(arg_name, value);
2181 op->add_result(res);
2183 }
else if(!value.empty()) {
2184 op->add_result(value, result_count);
2186 collected += result_count;
2188 }
else if(!rest.empty()) {
2189 op->add_result(rest, result_count);
2192 collected += result_count;
2196 while(min_num > collected && !args.empty()) {
2197 std::string current_ = args.back();
2199 op->add_result(current_, result_count);
2201 collected += result_count;
2204 if(min_num > collected) {
2205 throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
2209 if(max_num > collected || op->get_allow_extra_args()) {
2212 while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
2213 _recognize(args.back(),
false) == detail::Classifier::NONE) {
2215 if(remreqpos >= args.size()) {
2219 std::string arg = args.back();
2220 arg = op->_validate(arg, 0);
2225 op->add_result(args.back(), result_count);
2228 collected += result_count;
2232 if(!args.empty() &&
_recognize(args.back()) == detail::Classifier::POSITIONAL_MARK)
2235 if(min_num == 0 && max_num > 0 && collected == 0) {
2236 auto res = op->get_flag_value(arg_name, std::string{});
2237 op->add_result(res);
2242 if(min_num > 0 && (collected % op->get_type_size_max()) != 0) {
2243 if(op->get_type_size_max() != op->get_type_size_min()) {
2244 op->add_result(std::string{});
2246 throw ArgumentMismatch::PartialType(op->get_name(), op->get_type_size_min(), op->get_type_name());
2249 if(op->get_trigger_on_parse()) {
2254 args.push_back(rest);
2266 if(!
name_.empty()) {
2268 missing_t extras = std::move(
missing_);
2281 auto *fallthrough_parent =
parent_;
2282 while((fallthrough_parent->parent_ !=
nullptr) && (fallthrough_parent->get_name().empty())) {
2283 fallthrough_parent = fallthrough_parent->parent_;
2285 return fallthrough_parent;
2289 const App &base)
const {
2290 static const std::string estring;
2295 if(subc.get() != &subcom) {
2296 if(subc->disabled_) {
2300 if(subc->check_name(subcom.
get_name())) {
2304 if(!subc->get_name().empty()) {
2306 return subc->get_name();
2309 for(
const auto &les : subcom.
aliases_) {
2310 if(subc->check_name(les)) {
2315 for(
const auto &les : subc->aliases_) {
2321 if(subc->get_name().empty()) {
2323 if(!cmpres.empty()) {
2330 if(!cmpres.empty()) {
2341 missing_.emplace_back(val_type, val);
2346 if(subc->name_.empty() && subc->allow_extras_) {
2347 subc->missing_.emplace_back(val_type, val);
2352 missing_.emplace_back(val_type, val);
2356 if(opt ==
nullptr) {
2362 if(app == subc.get()) {
2377 std::find_if(std::begin(
options_), std::end(
options_), [opt](
const Option_p &v) {
return v.get() == opt; });
2378 if(iterator != std::end(
options_)) {
2379 const auto &opt_p = *iterator;
2380 if(std::find_if(std::begin(app->
options_), std::end(app->
options_), [&opt_p](
const Option_p &v) {
2381 return (*v == *opt_p);
2384 app->
options_.push_back(std::move(*iterator));
2394CLI11_INLINE
void TriggerOn(
App *trigger_app,
App *app_to_enable) {
2400CLI11_INLINE
void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) {
2401 for(
auto &app : apps_to_enable) {
2402 app->enabled_by_default(
false);
2403 app->disabled_by_default();
2406 trigger_app->preparse_callback([apps_to_enable](std::size_t) {
2407 for(
const auto &app : apps_to_enable) {
2408 app->disabled(
false);
2413CLI11_INLINE
void TriggerOff(App *trigger_app, App *app_to_enable) {
2414 app_to_enable->disabled_by_default(
false);
2415 app_to_enable->enabled_by_default();
2416 trigger_app->preparse_callback([app_to_enable](std::size_t) { app_to_enable->disabled(); });
2419CLI11_INLINE
void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable) {
2420 for(
auto &app : apps_to_enable) {
2421 app->disabled_by_default(
false);
2422 app->enabled_by_default();
2425 trigger_app->preparse_callback([apps_to_enable](std::size_t) {
2426 for(
const auto &app : apps_to_enable) {
2432CLI11_INLINE
void deprecate_option(Option *opt,
const std::string &replacement) {
2433 Validator deprecate_warning{[opt, replacement](std::string &) {
2434 std::cout << opt->get_name() <<
" is deprecated please use '" << replacement
2436 return std::string();
2439 deprecate_warning.application_index(0);
2440 opt->check(deprecate_warning);
2441 if(!replacement.empty()) {
2442 opt->description(opt->get_description() +
" DEPRECATED: please use '" + replacement +
"' instead");
2446CLI11_INLINE
void retire_option(App *app, Option *opt) {
2448 auto *option_copy = temp.add_option(opt->get_name(
false,
true))
2449 ->type_size(opt->get_type_size_min(), opt->get_type_size_max())
2450 ->expected(opt->get_expected_min(), opt->get_expected_max())
2451 ->allow_extra_args(opt->get_allow_extra_args());
2453 app->remove_option(opt);
2454 auto *opt2 = app->add_option(option_copy->get_name(
false,
true),
"option has been retired and has no effect");
2455 opt2->type_name(
"RETIRED")
2456 ->default_str(
"RETIRED")
2457 ->type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max())
2458 ->expected(option_copy->get_expected_min(), option_copy->get_expected_max())
2459 ->allow_extra_args(option_copy->get_allow_extra_args());
2463 Validator retired_warning{[opt2](std::string &) {
2464 std::cout <<
"WARNING " << opt2->get_name() <<
" is retired and has no effect\n";
2465 return std::string();
2469 retired_warning.application_index(0);
2470 opt2->check(retired_warning);
2473CLI11_INLINE
void retire_option(App &app, Option *opt) { retire_option(&app, opt); }
2475CLI11_INLINE
void retire_option(App *app,
const std::string &option_name) {
2477 auto *opt = app->get_option_no_throw(option_name);
2478 if(opt !=
nullptr) {
2479 retire_option(app, opt);
2482 auto *opt2 = app->add_option(option_name,
"option has been retired and has no effect")
2483 ->type_name(
"RETIRED")
2485 ->default_str(
"RETIRED");
2488 Validator retired_warning{[opt2](std::string &) {
2489 std::cout <<
"WARNING " << opt2->get_name() <<
" is retired and has no effect\n";
2490 return std::string();
2494 retired_warning.application_index(0);
2495 opt2->check(retired_warning);
2498CLI11_INLINE
void retire_option(App &app,
const std::string &option_name) { retire_option(&app, option_name); }
2500namespace FailureMessage {
2502CLI11_INLINE std::string simple(
const App *app,
const Error &e) {
2503 std::string header = std::string(e.what()) +
"\n";
2504 std::vector<std::string> names;
2507 if(app->get_help_ptr() !=
nullptr)
2508 names.push_back(app->get_help_ptr()->get_name());
2510 if(app->get_help_all_ptr() !=
nullptr)
2511 names.push_back(app->get_help_all_ptr()->get_name());
2515 header +=
"Run with " + detail::join(names,
" or ") +
" for more information.\n";
2520CLI11_INLINE std::string help(
const App *app,
const Error &e) {
2521 std::string header = std::string(
"ERROR: ") + e.get_name() +
": " + e.what() +
"\n";
2522 header += app->help();
Creates a command line program, with very few defaults.
Definition App.hpp:98
CLI11_NODISCARD Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
Definition App_inl.hpp:874
bool subcommand_fallthrough_
Allow subcommands to fallthrough, so that parent commands can trigger other subcommands after subcomm...
Definition App.hpp:240
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_inl.hpp:704
CLI11_NODISCARD std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition App_inl.hpp:800
CLI11_NODISCARD std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition App_inl.hpp:1014
CLI11_NODISCARD bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition App_inl.hpp:1785
CLI11_NODISCARD detail::Classifier _recognize(const std::string ¤t, bool ignore_used_subcommands=true) const
Selects a Classifier enum based on the type of the current argument.
Definition App_inl.hpp:1127
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
Definition App_inl.hpp:122
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
Definition App_inl.hpp:278
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_inl.hpp:2277
bool allow_non_standard_options_
indicator that the subcommand should allow non-standard option arguments, such as -single_dash_flag
Definition App.hpp:272
Option * config_ptr_
Pointer to the config option.
Definition App.hpp:306
CLI11_NODISCARD bool get_allow_non_standard_option_names() const
Get the status of allowing non standard option names.
Definition App.hpp:1180
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:421
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
Definition App_inl.hpp:2339
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition App.hpp:287
NameMatch
enumeration of matching possibilities
Definition App.hpp:1248
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Definition App_inl.hpp:148
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition App.hpp:284
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition App.hpp:227
CLI11_NODISCARD std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition App_inl.hpp:982
CLI11_NODISCARD std::vector< std::string > remaining_for_passthrough(bool recurse=false) const
This returns the missing options in a form ready for processing by another command line program.
Definition App_inl.hpp:1008
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition App.hpp:278
CLI11_NODISCARD App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
Definition App_inl.hpp:555
std::string usage_
Usage to put after program/subcommand description in the help output INHERITABLE.
Definition App.hpp:164
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition App.hpp:154
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition App_inl.hpp:1293
CLI11_NODISCARD std::size_t count_all() const
Definition App_inl.hpp:564
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition App.hpp:131
Option * set_version_flag(std::string flag_name="", const std::string &versionString="", const std::string &version_help="Display program version information and exit")
Set a version flag and version display string, replace the existing one if present.
Definition App_inl.hpp:311
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
Definition App_inl.hpp:782
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1202
void _configure()
Definition App_inl.hpp:1063
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition App_inl.hpp:1773
Option * add_flag_function(std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
Definition App_inl.hpp:387
void parse(int argc, const char *const *argv)
Definition App_inl.hpp:594
void _process_config_file()
Read and process a configuration file (main app only)
Definition App_inl.hpp:1184
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition App.hpp:170
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition App_inl.hpp:1489
config_extras_mode allow_config_extras_
Definition App.hpp:119
CLI11_NODISCARD bool check_name(std::string name_to_check) const
Definition App_inl.hpp:926
Option * version_ptr_
A pointer to a version flag if there is one.
Definition App.hpp:182
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition App.hpp:1208
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
Definition App_inl.hpp:485
App * parent_
A pointer to the parent if this is a subcommand.
Definition App.hpp:293
std::set< Option * > exclude_options_
Definition App.hpp:212
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition App_inl.hpp:2259
CLI::App_p get_subcommand_ptr(App *subcom) const
Check to see if a subcommand is part of this command and get a shared_ptr to it.
Definition App_inl.hpp:530
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition App.hpp:144
virtual void pre_callback()
Definition App.hpp:889
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition App.hpp:655
void _validate() const
Definition App_inl.hpp:1028
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition App.hpp:109
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition App.hpp:205
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition App.hpp:233
missing_t missing_
Definition App.hpp:199
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
Definition App_inl.hpp:1083
bool allow_prefix_matching_
indicator to allow subcommands to match with prefix matching
Definition App.hpp:275
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition App.hpp:281
CLI11_NODISCARD NameMatch check_name_detail(std::string name_to_check) const
Definition App_inl.hpp:931
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition App_inl.hpp:1220
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition App.hpp:188
void _parse_stream(std::istream &input)
Internal function to parse a stream.
Definition App_inl.hpp:1551
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition App_inl.hpp:910
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:125
CLI11_NODISCARD const std::string & _compare_subcommand_names(const App &subcom, const App &base) const
Helper function to run through all possible comparisons of subcommand names to check there is no over...
Definition App_inl.hpp:2288
void clear()
Reset the parsed data.
Definition App_inl.hpp:578
App * enabled_by_default(bool enable=true)
Definition App.hpp:432
App * get_subcommand(const App *subcom) const
Definition App_inl.hpp:501
CLI11_NODISCARD std::string version() const
Displays a version string.
Definition App_inl.hpp:814
CLI11_NODISCARD App * get_subcommand_no_throw(std::string subcom) const noexcept
Definition App_inl.hpp:517
bool _add_flag_like_result(Option *op, const ConfigItem &item, const std::vector< std::string > &inputs)
store the results for a flag like option
Definition App_inl.hpp:1570
std::vector< Option_p > options_
The list of options, stored locally.
Definition App.hpp:157
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition App.hpp:179
bool validate_optional_arguments_
If set to true optional vector arguments are validated before assigning INHERITABLE.
Definition App.hpp:265
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition App.hpp:147
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
Definition App_inl.hpp:431
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition App_inl.hpp:30
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition App_inl.hpp:454
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition App.hpp:374
Option * add_flag_callback(std::string flag_name, std::function< void(void)> function, std::string flag_description="")
Add option for callback that is triggered with a true flag and takes no arguments.
Definition App_inl.hpp:370
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition App.hpp:251
void _process()
Process callbacks and such.
Definition App_inl.hpp:1421
bool immediate_callback_
Definition App.hpp:138
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition App_inl.hpp:1731
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
Definition App_inl.hpp:87
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
Definition App_inl.hpp:2355
void _process_extras()
Throw an error if anything is left over and should not be.
Definition App_inl.hpp:1460
CLI11_NODISCARD bool _valid_subcommand(const std::string ¤t, bool ignore_used=true) const
Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached.
Definition App_inl.hpp:1110
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition App.hpp:259
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition App_inl.hpp:969
void _parse_config(const std::vector< ConfigItem > &args)
Definition App_inl.hpp:1562
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition App.hpp:290
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition App.hpp:299
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition App.hpp:208
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition App_inl.hpp:1795
bool ignore_case_
If true, the program name is not case-sensitive INHERITABLE.
Definition App.hpp:230
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1140
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type, bool local_processing_only)
Definition App_inl.hpp:2009
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition App.hpp:141
std::string group_
The group membership INHERITABLE.
Definition App.hpp:296
App * alias(std::string app_name)
Set an alias for the app.
Definition App_inl.hpp:104
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition App.hpp:134
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition App.hpp:176
Option * set_config(std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false)
Set a configuration ini file option, or clear it if no name passed.
Definition App_inl.hpp:402
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
Definition App_inl.hpp:134
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
Definition App_inl.hpp:762
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:940
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition App.hpp:1199
bool _parse_subcommand(std::vector< std::string > &args)
Definition App_inl.hpp:1969
bool fallthrough_
Definition App.hpp:237
std::set< Option * > need_options_
Definition App.hpp:220
std::vector< const Option * > get_options(const std::function< bool(const Option *)> filter={}) const
Get the list of options (user facing function, so returns raw pointers), has optional filter function...
Definition App_inl.hpp:832
std::set< App * > need_subcommands_
Definition App.hpp:216
bool prefix_command_
If true, cease processing on an unrecognized option (implies allow_extras) INHERITABLE.
Definition App.hpp:122
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition App_inl.hpp:162
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition App.hpp:202
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition App_inl.hpp:1497
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition App.hpp:262
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition App_inl.hpp:1631
void _process_help_flags(CallbackPriority priority, bool trigger_help=false, bool trigger_all_help=false) const
Definition App_inl.hpp:1271
startup_mode default_startup
Definition App.hpp:256
void _process_callbacks(CallbackPriority priority)
Process callbacks. Runs on all subcommands.
Definition App_inl.hpp:1242
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition App.hpp:115
CLI11_NODISCARD char ** ensure_utf8(char **argv)
Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
Definition App_inl.hpp:65
CLI11_NODISCARD App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition App_inl.hpp:1933
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1229
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition App.hpp:398
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition App.hpp:185
Option * set_help_all_flag(std::string help_name="", const std::string &help_description="")
Set a help all flag, replaced the existing one if present.
Definition App_inl.hpp:294
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition App.hpp:243
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
Definition App.hpp:309
Usually something like –help-all on command line.
Definition Error.hpp:178
-h or –help on command line
Definition Error.hpp:172
-v or –version on command line
Definition Error.hpp:185
All errors derive from this one.
Definition Error.hpp:73
Thrown when an excludes option is present.
Definition Error.hpp:301
Thrown when parsing an INI file and it is missing.
Definition Error.hpp:198
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition Error.hpp:96
Thrown when validation fails before parsing.
Definition Error.hpp:334
Thrown when an option already exists.
Definition Error.hpp:144
CLI11_NODISCARD CallbackPriority get_callback_priority() const
The priority of callback.
Definition Option.hpp:161
CLI11_NODISCARD bool get_required() const
True if this is a required option.
Definition Option.hpp:137
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition Option.hpp:202
CLI11_NODISCARD MultiOptionPolicy get_multi_option_policy() const
The status of the multi option policy.
Definition Option.hpp:158
CLI11_NODISCARD bool get_configurable() const
The status of configurable.
Definition Option.hpp:146
bool required_
True if this is a required option.
Definition Option.hpp:76
CLI11_NODISCARD bool get_disable_flag_override() const
The status of configurable.
Definition Option.hpp:149
CLI11_NODISCARD const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:134
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition Option_inl.hpp:25
CRTP * required(bool value=true)
Set the option as required.
Definition Option.hpp:118
Definition Option.hpp:259
Option * expected(int value)
Set the number of expected arguments.
Definition Option_inl.hpp:38
CLI11_NODISCARD bool get_positional() const
True if the argument can be given directly.
Definition Option.hpp:628
CLI11_NODISCARD bool check_name(const std::string &name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
Definition Option_inl.hpp:381
@ callback_run
the callback has been executed
Option * callback_priority(CallbackPriority value=CallbackPriority::Normal)
Definition Option.hpp:448
std::set< Option * > needs_
A list of options that are required with this option.
Definition Option.hpp:326
void run_callback()
Process the callback.
Definition Option_inl.hpp:310
CLI11_NODISCARD bool check_sname(std::string name) const
Requires "-" to be removed from string.
Definition Option.hpp:681
CLI11_NODISCARD std::string get_name(bool positional=false, bool all_options=false) const
Gets a comma separated list of names. Will include / prefer the positional name if positional is true...
Definition Option_inl.hpp:257
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition Option.hpp:329
bool force_callback_
flag indicating that the option should force the callback regardless if any results present
Definition Option.hpp:369
CLI11_NODISCARD bool get_callback_run() const
See if the callback has been run already.
Definition Option.hpp:766
std::vector< std::string > fnames_
a list of flag names with specified default values;
Definition Option.hpp:278
CLI11_NODISCARD int get_items_expected_min() const
The total min number of expected string values to be used.
Definition Option.hpp:617
CLI11_NODISCARD bool check_lname(std::string name) const
Requires "--" to be removed from string.
Definition Option.hpp:686
CLI11_NODISCARD const results_t & results() const
Get the current complete results set.
Definition Option.hpp:712
CLI11_NODISCARD int get_items_expected_max() const
Get the maximum number of items expected to be returned and used for the callback.
Definition Option.hpp:620
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:389
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition Option_inl.hpp:244
CLI11_NODISCARD bool get_inject_separator() const
Return the inject_separator flag.
Definition Option.hpp:570
CLI11_NODISCARD std::string get_flag_value(const std::string &name, std::string input_value) const
Definition Option_inl.hpp:410
CLI11_NODISCARD const std::string & get_description() const
Get the description.
Definition Option.hpp:637
CLI11_NODISCARD bool empty() const
True if the option was not passed.
Definition Option.hpp:392
CLI11_NODISCARD int get_expected_min() const
The number of times the option expects to be included.
Definition Option.hpp:612
void clear()
Clear the parsed results (mostly for testing)
Definition Option.hpp:398
CLI11_NODISCARD int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:614
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition Option.hpp:808
std::string envname_
If given, check the environment for this option.
Definition Option.hpp:284
CLI11_NODISCARD bool get_allow_extra_args() const
Get the current value of allow extra args.
Definition Option.hpp:420
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition Option.hpp:275
Option * add_result(std::string s)
Puts a result at the end.
Definition Option_inl.hpp:456
CLI11_NODISCARD T as() const
Return the results as the specified type.
Definition Option.hpp:759
Thrown when counting a nonexistent option.
Definition Error.hpp:351
Anything that can error in Parse.
Definition Error.hpp:159
Thrown when a required option is missing.
Definition Error.hpp:228
Thrown when a requires option is missing.
Definition Error.hpp:294
Holds values to load into Options.
Definition ConfigFwd.hpp:29
std::vector< std::string > inputs
Listing of inputs.
Definition ConfigFwd.hpp:36
std::string name
This is the name.
Definition ConfigFwd.hpp:34
CLI11_NODISCARD std::string fullname() const
The list of parents and name joined by ".".
Definition ConfigFwd.hpp:40
bool multiline
indicator if a multiline vector separator was inserted
Definition ConfigFwd.hpp:38
std::vector< std::string > parents
This is the list of parents.
Definition ConfigFwd.hpp:31