61#define CLI11_VERSION_MAJOR 2
62#define CLI11_VERSION_MINOR 1
63#define CLI11_VERSION_PATCH 2
64#define CLI11_VERSION "2.1.2"
70#if !(defined(_MSC_VER) && __cplusplus == 199711L) && !defined(__INTEL_COMPILER)
71#if __cplusplus >= 201402L
73#if __cplusplus >= 201703L
75#if __cplusplus > 201703L
80#elif defined(_MSC_VER) && __cplusplus == 199711L
83#if _MSVC_LANG >= 201402L
85#if _MSVC_LANG > 201402L && _MSC_VER >= 1910
87#if __MSVC_LANG > 201703L && _MSC_VER >= 1910
94#if defined(CLI11_CPP14)
95#define CLI11_DEPRECATED(reason) [[deprecated(reason)]]
96#elif defined(_MSC_VER)
97#define CLI11_DEPRECATED(reason) __declspec(deprecated(reason))
99#define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason)))
107#if defined CLI11_CPP17 && defined __has_include && !defined CLI11_HAS_FILESYSTEM
108#if __has_include(<filesystem>)
110#if defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
111#define CLI11_HAS_FILESYSTEM 0
114#if defined __cpp_lib_filesystem && __cpp_lib_filesystem >= 201703
115#if defined _GLIBCXX_RELEASE && _GLIBCXX_RELEASE >= 9
116#define CLI11_HAS_FILESYSTEM 1
117#elif defined(__GLIBCXX__)
119#define CLI11_HAS_FILESYSTEM 0
121#define CLI11_HAS_FILESYSTEM 1
124#define CLI11_HAS_FILESYSTEM 0
130#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
134#include <sys/types.h>
147template <typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
150 return in << static_cast<typename std::underlying_type<T>::type>(item);
156using enums::operator<<;
164inline std::vector<std::string>
split(
const std::string &s,
char delim) {
165 std::vector<std::string> elems;
168 elems.emplace_back();
170 std::stringstream ss;
173 while(std::getline(ss, item, delim)) {
174 elems.push_back(item);
181template <
typename T> std::string
join(
const T &v, std::string delim =
",") {
182 std::ostringstream s;
183 auto beg = std::begin(v);
184 auto end = std::end(v);
188 s << delim << *beg++;
196 typename =
typename std::enable_if<!std::is_constructible<std::string, Callable>::value>::type>
197std::string
join(
const T &v, Callable func, std::string delim =
",") {
198 std::ostringstream s;
199 auto beg = std::begin(v);
200 auto end = std::end(v);
201 auto loc = s.tellp();
203 auto nloc = s.tellp();
214template <
typename T> std::string
rjoin(
const T &v, std::string delim =
",") {
215 std::ostringstream s;
216 for(std::size_t start = 0; start < v.size(); start++) {
219 s << v[v.size() - start - 1];
228 auto it = std::find_if(
str.begin(),
str.end(), [](
char ch) { return !std::isspace<char>(ch, std::locale()); });
229 str.erase(
str.begin(), it);
234inline std::string &
ltrim(std::string &
str,
const std::string &filter) {
235 auto it = std::find_if(
str.begin(),
str.end(), [&filter](
char ch) { return filter.find(ch) == std::string::npos; });
236 str.erase(
str.begin(), it);
242 auto it = std::find_if(
str.rbegin(),
str.rend(), [](
char ch) { return !std::isspace<char>(ch, std::locale()); });
243 str.erase(it.base(),
str.end());
248inline std::string &
rtrim(std::string &
str,
const std::string &filter) {
250 std::find_if(
str.rbegin(),
str.rend(), [&filter](
char ch) { return filter.find(ch) == std::string::npos; });
251 str.erase(it.base(),
str.end());
259inline std::string &
trim(std::string &
str,
const std::string filter) {
return ltrim(
rtrim(
str, filter), filter); }
269 if(
str.length() > 1 && (
str.front() ==
'"' ||
str.front() ==
'\'')) {
270 if(
str.front() ==
str.back()) {
282inline std::string
fix_newlines(
const std::string &leader, std::string input) {
283 std::string::size_type n = 0;
284 while(n != std::string::npos && n < input.size()) {
285 n = input.find(
'\n', n);
286 if(n != std::string::npos) {
287 input = input.substr(0, n + 1) + leader + input.substr(n + 1);
295inline std::string
trim_copy(
const std::string &
str,
const std::string &filter) {
297 return trim(s, filter);
300inline std::ostream &
format_help(std::ostream &out, std::string name,
const std::string &description, std::size_t wid) {
302 out << std::setw(static_cast<int>(wid)) << std::left << name;
303 if(!description.empty()) {
304 if(name.length() >= wid)
305 out <<
"\n" << std::setw(
static_cast<int>(wid)) <<
"";
306 for(
const char c : description) {
309 out << std::setw(static_cast<int>(wid)) <<
"";
318inline std::ostream &
format_aliases(std::ostream &out,
const std::vector<std::string> &aliases, std::size_t wid) {
319 if(!aliases.empty()) {
320 out << std::setw(static_cast<int>(wid)) <<
" aliases: ";
322 for(
const auto &alias : aliases) {
337template <
typename T>
bool valid_first_char(T c) {
return ((c !=
'-') && (c !=
'!') && (c !=
' ') && c !=
'\n'); }
344 return ((c !=
'=') && (c !=
':') && (c !=
'{') && (c !=
' ') && c !=
'\n');
353 for(
auto c =
str.begin() + 1; c != e; ++c)
361 static const std::string badChars(std::string(
"\n") +
'\0');
362 return (
str.find_first_of(badChars) == std::string::npos);
367 static const std::string
sep(
"%%");
373 return std::all_of(
str.begin(),
str.end(), [](
char c) { return std::isalpha(c, std::locale()); });
378 std::transform(std::begin(
str), std::end(
str), std::begin(
str), [](
const std::string::value_type &x) {
379 return std::tolower(x, std::locale());
386 str.erase(std::remove(std::begin(
str), std::end(
str),
'_'), std::end(
str));
393 std::size_t start_pos = 0;
395 while((start_pos =
str.find(from, start_pos)) != std::string::npos) {
396 str.replace(start_pos, from.length(), to);
397 start_pos += to.length();
405 return (flags.find_first_of(
"{!") != std::string::npos);
409 auto loc = flags.find_first_of(
'{', 2);
410 while(loc != std::string::npos) {
411 auto finish = flags.find_first_of(
"},", loc + 1);
412 if((finish != std::string::npos) && (flags[finish] ==
'}')) {
413 flags.erase(flags.begin() +
static_cast<std::ptrdiff_t
>(loc),
414 flags.begin() +
static_cast<std::ptrdiff_t
>(finish) + 1);
416 loc = flags.find_first_of(
'{', loc + 1);
418 flags.erase(std::remove(flags.begin(), flags.end(),
'!'), flags.end());
423 const std::vector<std::string> names,
426 auto it = std::end(names);
430 it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) {
435 it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) {
442 it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) {
446 it = std::find(std::begin(names), std::end(names), name);
449 return (it != std::end(names)) ? (it - std::begin(names)) : (-1);
454template <
typename Callable>
inline std::string
find_and_modify(std::string
str, std::string trigger, Callable modify) {
455 std::size_t start_pos = 0;
456 while((start_pos =
str.find(trigger, start_pos)) != std::string::npos) {
457 start_pos = modify(
str, start_pos);
464inline std::vector<std::string>
split_up(std::string
str,
char delimiter =
'\0') {
466 const std::string delims(
"\'\"`");
467 auto find_ws = [delimiter](
char ch) {
468 return (delimiter ==
'\0') ? (std::isspace<char>(ch, std::locale()) != 0) : (ch == delimiter);
472 std::vector<std::string> output;
473 bool embeddedQuote =
false;
475 while(!
str.empty()) {
476 if(delims.find_first_of(
str[0]) != std::string::npos) {
478 auto end =
str.find_first_of(keyChar, 1);
479 while((end != std::string::npos) && (
str[end - 1] ==
'\\')) {
480 end =
str.find_first_of(keyChar, end + 1);
481 embeddedQuote =
true;
483 if(end != std::string::npos) {
484 output.push_back(
str.substr(1, end - 1));
485 if(end + 2 <
str.size()) {
486 str =
str.substr(end + 2);
492 output.push_back(
str.substr(1));
496 auto it = std::find_if(std::begin(
str), std::end(
str), find_ws);
497 if(it != std::end(
str)) {
498 std::string value = std::string(
str.begin(), it);
499 output.push_back(value);
500 str = std::string(it + 1,
str.end());
502 output.push_back(
str);
508 output.back() =
find_and_replace(output.back(), std::string(
"\\") + keyChar, std::string(1, keyChar));
509 embeddedQuote =
false;
521 auto next =
str[offset + 1];
522 if((next ==
'\"') || (next ==
'\'') || (next ==
'`')) {
523 auto astart =
str.find_last_of(
"-/ \"\'`", offset - 1);
524 if(astart != std::string::npos) {
525 if(
str[astart] == ((
str[offset] ==
'=') ?
'-' :
'/'))
534 if((
str.front() !=
'"' &&
str.front() !=
'\'') ||
str.front() !=
str.back()) {
535 char quote =
str.find(
'"') <
str.find(
'\'') ?
'\'' :
'"';
536 if(
str.find(
' ') != std::string::npos) {
537 str.insert(0, 1, quote);
538 str.append(1, quote);
551#define CLI11_ERROR_DEF(parent, name) \
553 name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {} \
554 name(std::string ename, std::string msg, ExitCodes exit_code) \
555 : parent(std::move(ename), std::move(msg), exit_code) {} \
558 name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \
559 name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {}
562#define CLI11_ERROR_SIMPLE(name) \
563 explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {}
596class Error :
public std::runtime_error {
597 int actual_exit_code;
598 std::string error_name{
"Error"};
603 std::string
get_name()
const {
return error_name; }
606 : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {}
608 Error(std::string name, std::string msg,
ExitCodes exit_code) :
Error(name, msg, static_cast<int>(exit_code)) {}
636 name +
": You can't change expected arguments after you've changed the multi option policy!");
642 return IncorrectConstruction(name +
": multi_option_policy only works for flags and exact value options");
653 return BadNameString(
"Must have a name, not just dashes: " + name);
656 return BadNameString(
"Only one positional name allowed, remove: " + name);
726 :
ConversionError("The value " + member + " is not an allowed value for " + name) {}
728 :
ConversionError(
"Could not convert: " + name +
" = " + detail::join(results)) {}
749 if(min_subcom == 1) {
752 return RequiredError(
"Requires at least " + std::to_string(min_subcom) +
" subcommands",
756 Option(std::size_t min_option, std::size_t max_option, std::size_t used,
const std::string &option_list) {
757 if((min_option == 1) && (max_option == 1) && (used == 0))
758 return RequiredError(
"Exactly 1 option from [" + option_list +
"]");
759 if((min_option == 1) && (max_option == 1) && (used > 1)) {
760 return RequiredError(
"Exactly 1 option from [" + option_list +
"] is required and " + std::to_string(used) +
764 if((min_option == 1) && (used == 0))
765 return RequiredError(
"At least 1 option from [" + option_list +
"]");
766 if(used < min_option) {
767 return RequiredError(
"Requires at least " + std::to_string(min_option) +
" options used and only " +
768 std::to_string(used) +
"were given from [" + option_list +
"]",
772 return RequiredError(
"Requires at most 1 options be given from [" + option_list +
"]",
775 return RequiredError(
"Requires at most " + std::to_string(max_option) +
" options be used and " +
776 std::to_string(used) +
"were given from [" + option_list +
"]",
786 :
ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name +
787 ", got " + std::to_string(received))
788 : ("Expected at least " + std::to_string(-expected) + " arguments to " + name +
789 ", got " + std::to_string(received)),
793 return ArgumentMismatch(name +
": At least " + std::to_string(num) +
" required but received " +
794 std::to_string(received));
797 return ArgumentMismatch(name +
": At Most " + std::to_string(num) +
" required but received " +
798 std::to_string(received));
801 return ArgumentMismatch(name +
": " + std::to_string(num) +
" required " + type +
" missing");
826 :
ExtrasError((args.size() > 1 ? "The following arguments were not expected: "
827 : "The following argument was not expected: ") +
828 detail::rjoin(args, " "),
830 ExtrasError(
const std::string &name, std::vector<std::string> args)
832 (args.size() > 1 ?
"The following arguments were not expected: "
833 :
"The following argument was not expected: ") +
834 detail::rjoin(args,
" "),
844 return ConfigError(item +
": This option is not allowed in a configuration file");
871#undef CLI11_ERROR_DEF
872#undef CLI11_ERROR_SIMPLE
896template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
905template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
908template <
typename T>
struct is_bool : std::false_type {};
911template <>
struct is_bool<bool> : std::true_type {};
917template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
920template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
943template <
typename T>
struct element_type<T, typename std::enable_if<is_copyable_ptr<T>::value>::type> {
944 using type =
typename std::pointer_traits<T>::element_type;
952template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
954 using first_type =
typename std::remove_const<value_type>::type;
958 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
959 return std::forward<Q>(pair_value);
962 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
963 return std::forward<Q>(pair_value);
972 conditional_t<false,
void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
975 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
976 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
979 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::get<0>(std::forward<Q>(pair_value))) {
980 return std::get<0>(std::forward<Q>(pair_value));
983 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::get<1>(std::forward<Q>(pair_value))) {
984 return std::get<1>(std::forward<Q>(pair_value));
995#pragma GCC diagnostic push
996#pragma GCC diagnostic ignored "-Wnarrowing"
1000 template <
typename TT,
typename CC>
1001 static auto test(
int, std::true_type) ->
decltype(
1004#pragma diag_suppress 2361
1006 TT { std::declval<CC>() }
1008#pragma diag_default 2361
1011 std::is_move_assignable<TT>());
1013 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
1015 template <
typename,
typename>
static auto test(...) -> std::false_type;
1018 static constexpr bool value =
decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
1021#pragma GCC diagnostic pop
1028 template <
typename TT,
typename SS>
1029 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
1031 template <
typename,
typename>
static auto test(...) -> std::false_type;
1034 static constexpr bool value =
decltype(test<T, S>(0))::value;
1039 template <
typename TT,
typename SS>
1040 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
1042 template <
typename,
typename>
static auto test(...) -> std::false_type;
1045 static constexpr bool value =
decltype(test<T, S>(0))::value;
1050 template <
typename TT>
1051 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
1053 template <
typename>
static auto test(...) -> std::false_type;
1056 static constexpr bool value =
decltype(test<T>(0))::value;
1060template <typename T, enable_if_t<is_istreamable<T>::value,
detail::enabler> = detail::dummy>
1062 std::istringstream is;
1065 return !is.fail() && !is.rdbuf()->in_avail();
1068template <typename T, enable_if_t<!is_istreamable<T>::value,
detail::enabler> = detail::dummy>
1069bool from_stream(
const std::string & , T & ) {
1079template <
typename T>
1083 void_t<typename T::value_type,
1084 decltype(std::declval<T>().end()),
1085 decltype(std::declval<T>().clear()),
1086 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
1087 std::declval<const typename T::value_type &>()))>,
1089 :
public conditional_t<std::is_constructible<T, std::string>::value, std::false_type, std::true_type> {};
1097template <
typename T>
1100 conditional_t<false,
void_t<decltype(std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
1101 :
public std::true_type {};
1104template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
1107template <
typename T>
1112 template <
typename SS>
1115 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});
1116 template <
typename>
static auto test(...) -> std::false_type;
1119 static constexpr bool value =
decltype(test<S>(0))::value;
1123template <typename T, enable_if_t<std::is_convertible<T, std::string>::value,
detail::enabler> = detail::dummy>
1124auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
1125 return std::forward<T>(value);
1129template <
typename T,
1133 return std::string(value);
1137template <
typename T,
1139 is_ostreamable<T>::value,
1142 std::stringstream stream;
1144 return stream.str();
1148template <
typename T,
1150 !is_readable_container<typename std::remove_const<T>::type>::value,
1152std::string to_string(T &&) {
1153 return std::string{};
1157template <
typename T,
1158 enable_if_t<!std::is_constructible<std::string, T>::value && !is_ostreamable<T>::value &&
1159 is_readable_container<T>::value,
1160 detail::enabler> = detail::dummy>
1162 std::vector<std::string> defaults;
1163 auto cval = variable.begin();
1164 auto end = variable.end();
1165 while(cval != end) {
1169 return std::string(
"[" + detail::join(defaults) +
"]");
1173template <
typename T1,
1176 enable_if_t<std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
1178 return to_string(std::forward<T>(value));
1182template <
typename T1,
1187 return std::string{};
1190template <typename T, enable_if_t<std::is_arithmetic<T>::value,
detail::enabler> = detail::dummy>
1192 return std::to_string(value);
1195template <typename T, enable_if_t<std::is_enum<T>::value,
detail::enabler> = detail::dummy>
1196std::string value_string(
const T &value) {
1197 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
1200template <
typename T,
1201 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
1207template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
using type = def; };
1210template <
typename T,
typename def>
struct wrapped_type<T, def, typename std::enable_if<is_wrapper<T>::value>::type> {
1211 using type =
typename T::value_type;
1215template <
typename T,
typename Enable =
void>
struct type_count_base {
static const int value{0}; };
1218template <
typename T>
1220 typename std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
1221 !std::is_void<T>::value>::type> {
1222 static constexpr int value{1};
1226template <
typename T>
1227struct type_count_base<T, typename std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
1228 static constexpr int value{std::tuple_size<T>::value};
1232template <
typename T>
struct type_count_base<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
1245template <
typename T,
typename Enable =
void>
struct type_count {
static const int value{0}; };
1248template <
typename T>
1250 typename std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
1251 !std::is_void<T>::value>::type> {
1252 static constexpr int value{1};
1256template <
typename T>
struct type_count<T, typename std::enable_if<is_complex<T>::value>::type> {
1257 static constexpr int value{2};
1261template <
typename T>
struct type_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
1266template <
typename T>
1268 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
1269 !is_mutable_container<T>::value>::type> {
1274template <
typename T, std::
size_t I>
1275constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size() {
1280template <
typename T, std::
size_t I>
1281 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size() {
1282 return subtype_count<typename std::tuple_element<I, T>::type>::value + tuple_type_size<T, I + 1>();
1286template <
typename T>
struct type_count<T, typename std::enable_if<is_tuple_like<T>::value>::type> {
1287 static constexpr int value{tuple_type_size<T, 0>()};
1291template <
typename T>
struct subtype_count {
1296template <
typename T,
typename Enable =
void>
struct type_count_min {
static const int value{0}; };
1299template <
typename T>
1300struct type_count_min<
1302 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
1303 !is_complex<T>::value && !std::is_void<T>::value>::type> {
1304 static constexpr int value{type_count<T>::value};
1308template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
1309 static constexpr int value{1};
1313template <
typename T>
1314struct type_count_min<
1316 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
1317 static constexpr int value{subtype_count_min<typename T::value_type>::value};
1321template <
typename T, std::
size_t I>
1322constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
1327template <
typename T, std::
size_t I>
1328 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
1329 return subtype_count_min<typename std::tuple_element<I, T>::type>::value + tuple_type_size_min<T, I + 1>();
1333template <
typename T>
struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value>::type> {
1334 static constexpr int value{tuple_type_size_min<T, 0>()};
1338template <
typename T>
struct subtype_count_min {
1339 static constexpr int value{is_mutable_container<T>::value
1341 : type_count_min<T>::value};
1345template <
typename T,
typename Enable =
void>
struct expected_count {
static const int value{0}; };
1348template <
typename T>
1349struct expected_count<T,
1350 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
1351 !std::is_void<T>::value>::type> {
1352 static constexpr int value{1};
1355template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
1360template <
typename T>
1361struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
1362 static constexpr int value{expected_count<typename T::value_type>::value};
1366enum class object_category :
int {
1369 unsigned_integral = 4,
1372 floating_point = 10,
1373 number_constructible = 12,
1374 double_constructible = 14,
1375 integer_constructible = 16,
1377 string_assignable = 23,
1378 string_constructible = 24,
1382 complex_number = 60,
1384 container_value = 80,
1391template <
typename T,
typename Enable =
void>
struct classify_object {
1392 static constexpr object_category value{object_category::other};
1396template <
typename T>
1397struct classify_object<
1399 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
1400 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
1401 static constexpr object_category value{object_category::integral_value};
1405template <
typename T>
1406struct classify_object<T,
1407 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
1408 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
1409 static constexpr object_category value{object_category::unsigned_integral};
1413template <
typename T>
1414struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
1415 static constexpr object_category value{object_category::char_value};
1419template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
1420 static constexpr object_category value{object_category::boolean_value};
1424template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
1425 static constexpr object_category value{object_category::floating_point};
1429template <
typename T>
1430struct classify_object<T,
1431 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
1432 std::is_assignable<T &, std::string>::value>::type> {
1433 static constexpr object_category value{object_category::string_assignable};
1437template <
typename T>
1438struct classify_object<
1440 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
1441 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
1442 std::is_constructible<T, std::string>::value>::type> {
1443 static constexpr object_category value{object_category::string_constructible};
1447template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
1448 static constexpr object_category value{object_category::enumeration};
1451template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
1452 static constexpr object_category value{object_category::complex_number};
1457template <
typename T>
struct uncommon_type {
1458 using type =
typename std::conditional<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
1459 !std::is_assignable<T &, std::string>::value &&
1460 !std::is_constructible<T, std::string>::value && !is_complex<T>::value &&
1461 !is_mutable_container<T>::value && !std::is_enum<T>::value,
1463 std::false_type>::type;
1464 static constexpr bool value = type::value;
1468template <
typename T>
1469struct classify_object<T,
1470 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
1471 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
1472 static constexpr object_category value{object_category::wrapper_value};
1476template <
typename T>
1477struct classify_object<T,
1478 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
1479 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
1480 is_direct_constructible<T, int>::value>::type> {
1481 static constexpr object_category value{object_category::number_constructible};
1485template <
typename T>
1486struct classify_object<T,
1487 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
1488 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
1489 is_direct_constructible<T, int>::value>::type> {
1490 static constexpr object_category value{object_category::integer_constructible};
1494template <
typename T>
1495struct classify_object<T,
1496 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
1497 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
1498 !is_direct_constructible<T, int>::value>::type> {
1499 static constexpr object_category value{object_category::double_constructible};
1503template <
typename T>
1504struct classify_object<
1506 typename std::enable_if<is_tuple_like<T>::value &&
1507 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
1508 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
1509 !is_direct_constructible<T, int>::value))>::type> {
1510 static constexpr object_category value{object_category::tuple_value};
1519template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
1520 static constexpr object_category value{object_category::container_value};
1529template <
typename T,
1530 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1535template <
typename T,
1536 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1537 classify_object<T>::value == object_category::integer_constructible,
1538 detail::enabler> = detail::dummy>
1543template <
typename T,
1544 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
1549template <
typename T,
1550 enable_if_t<classify_object<T>::value == object_category::floating_point ||
1551 classify_object<T>::value == object_category::number_constructible ||
1552 classify_object<T>::value == object_category::double_constructible,
1553 detail::enabler> = detail::dummy>
1559template <
typename T,
1560 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1566template <
typename T,
1567 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1573template <
typename T,
1574 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1580template <
typename T,
1581 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
1582 classify_object<T>::value <= object_category::other,
1583 detail::enabler> = detail::dummy>
1588template <
typename T,
1589 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
1590 detail::enabler> = detail::dummy>
1594template <
typename T,
1595 enable_if_t<classify_object<T>::value == object_category::container_value ||
1596 classify_object<T>::value == object_category::wrapper_value,
1597 detail::enabler> = detail::dummy>
1601template <
typename T,
1602 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
1603 detail::enabler> = detail::dummy>
1605 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
1609template <
typename T, std::
size_t I>
1610inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
1611 return std::string{};
1615template <
typename T, std::
size_t I>
1616inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
1617 std::string
str = std::string(type_name<
typename std::decay<
typename std::tuple_element<I, T>::type>::type>()) +
1618 ',' + tuple_name<T, I + 1>();
1625template <
typename T,
1629 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
1630 tname.push_back(
']');
1635template <
typename T,
1637 classify_object<T>::value == object_category::wrapper_value,
1640 return type_name<typename T::value_type>();
1646template <typename T, enable_if_t<std::is_unsigned<T>::value,
detail::enabler> = detail::dummy>
1651 char *val =
nullptr;
1652 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
1653 output =
static_cast<T
>(output_ll);
1654 return val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll;
1658template <typename T, enable_if_t<std::is_signed<T>::value,
detail::enabler> = detail::dummy>
1659bool integral_conversion(
const std::string &input, T &output)
noexcept {
1663 char *val =
nullptr;
1664 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1665 output =
static_cast<T
>(output_ll);
1666 return val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll;
1671 static const std::string trueString(
"true");
1672 static const std::string falseString(
"false");
1673 if(val == trueString) {
1676 if(val == falseString) {
1679 val = detail::to_lower(val);
1681 if(val.size() == 1) {
1682 if(val[0] >=
'1' && val[0] <=
'9') {
1683 return (
static_cast<std::int64_t
>(val[0]) -
'0');
1698 throw std::invalid_argument(
"unrecognized character");
1702 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1704 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1707 ret = std::stoll(val);
1713template <
typename T,
1715 classify_object<T>::value == object_category::unsigned_integral,
1722template <
typename T,
1724bool lexical_cast(
const std::string &input, T &output) {
1725 if(input.size() == 1) {
1726 output =
static_cast<T
>(input[0]);
1729 return integral_conversion(input, output);
1733template <
typename T,
1734 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1735bool lexical_cast(
const std::string &input, T &output) {
1740 }
catch(
const std::invalid_argument &) {
1742 }
catch(
const std::out_of_range &) {
1745 output = (input[0] !=
'-');
1751template <
typename T,
1752 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1753bool lexical_cast(
const std::string &input, T &output) {
1757 char *val =
nullptr;
1758 auto output_ld = std::strtold(input.c_str(), &val);
1759 output =
static_cast<T
>(output_ld);
1760 return val == (input.c_str() + input.size());
1764template <
typename T,
1765 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1766bool lexical_cast(
const std::string &input, T &output) {
1767 using XC =
typename wrapped_type<T, double>::type;
1770 bool worked =
false;
1771 auto nloc = str1.find_last_of(
"+-");
1772 if(nloc != std::string::npos && nloc > 0) {
1773 worked = detail::lexical_cast(str1.substr(0, nloc), x);
1774 str1 = str1.substr(nloc);
1775 if(str1.back() ==
'i' || str1.back() ==
'j')
1777 worked = worked && detail::lexical_cast(str1, y);
1779 if(str1.back() ==
'i' || str1.back() ==
'j') {
1781 worked = detail::lexical_cast(str1, y);
1784 worked = detail::lexical_cast(str1, x);
1796template <
typename T,
1797 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1798bool lexical_cast(
const std::string &input, T &output) {
1806 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1807bool lexical_cast(
const std::string &input, T &output) {
1813template <
typename T,
1814 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1815bool lexical_cast(
const std::string &input, T &output) {
1816 typename std::underlying_type<T>::type val;
1820 output =
static_cast<T
>(val);
1825template <
typename T,
1826 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1827 std::is_assignable<T &, typename T::value_type>::value,
1828 detail::enabler> = detail::dummy>
1829bool lexical_cast(
const std::string &input, T &output) {
1830 typename T::value_type val;
1838template <
typename T,
1839 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1840 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1841 detail::enabler> = detail::dummy>
1842bool lexical_cast(
const std::string &input, T &output) {
1843 typename T::value_type val;
1854 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1855bool lexical_cast(
const std::string &input, T &output) {
1873 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1874bool lexical_cast(
const std::string &input, T &output) {
1886 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1887bool lexical_cast(
const std::string &input, T &output) {
1897template <
typename T,
1898 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1899 detail::enabler> = detail::dummy>
1900bool lexical_cast(
const std::string &input, T &output) {
1904#pragma warning(push)
1905#pragma warning(disable : 4800)
1923template <
typename T,
1924 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value,
1925 detail::enabler> = detail::dummy>
1926bool lexical_cast(
const std::string &input, T &output) {
1927 static_assert(is_istreamable<T>::value,
1928 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1929 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1935template <
typename AssignTo,
1937 enable_if_t<std::is_same<AssignTo, ConvertTo>::value &&
1938 (classify_object<AssignTo>::value == object_category::string_assignable ||
1939 classify_object<AssignTo>::value == object_category::string_constructible),
1940 detail::enabler> = detail::dummy>
1946template <
typename AssignTo,
1949 classify_object<AssignTo>::value != object_category::string_assignable &&
1950 classify_object<AssignTo>::value != object_category::string_constructible,
1952bool lexical_assign(
const std::string &input, AssignTo &output) {
1954 output = AssignTo{};
1962template <
typename AssignTo,
1964 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1965 classify_object<AssignTo>::value == object_category::wrapper_value,
1966 detail::enabler> = detail::dummy>
1969 typename AssignTo::value_type emptyVal{};
1978template <
typename AssignTo,
1980 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1981 classify_object<AssignTo>::value != object_category::wrapper_value &&
1982 std::is_assignable<AssignTo &, int>::value,
1983 detail::enabler> = detail::dummy>
1998template <
typename AssignTo,
2000 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
2001 detail::enabler> = detail::dummy>
2004 bool parse_result = (!input.empty()) ? lexical_cast<ConvertTo>(input, val) :
true;
2008 return parse_result;
2015 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
2016 std::is_move_assignable<AssignTo>::value,
2017 detail::enabler> = detail::dummy>
2020 bool parse_result = input.empty() ? true : lexical_cast<ConvertTo>(input, val);
2022 output = AssignTo(val);
2024 return parse_result;
2028template <
typename AssignTo,
2030 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
2031 classify_object<AssignTo>::value <= object_category::wrapper_value,
2032 detail::enabler> = detail::dummy>
2033bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2034 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
2039template <
typename AssignTo,
2041 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
2042 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
2043 detail::enabler> = detail::dummy>
2044bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2046 typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type v1;
2047 typename std::tuple_element<1, ConvertTo>::type v2;
2048 bool retval = lexical_assign<decltype(v1), decltype(v1)>(strings[0], v1);
2049 if(strings.size() > 1) {
2050 retval = retval && lexical_assign<decltype(v2), decltype(v2)>(strings[1], v2);
2053 output = AssignTo{v1, v2};
2059template <
class AssignTo,
2061 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
2062 type_count<ConvertTo>::value == 1,
2063 detail::enabler> = detail::dummy>
2064bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2065 output.erase(output.begin(), output.end());
2066 for(
const auto &elem : strings) {
2067 typename AssignTo::value_type out;
2068 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
2072 output.insert(output.end(), std::move(out));
2074 return (!output.empty());
2078template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
2079bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
2081 if(strings.size() >= 2 && !strings[1].empty()) {
2082 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
2084 auto str1 = strings[1];
2085 if(str1.back() ==
'i' || str1.back() ==
'j') {
2088 auto worked = detail::lexical_cast(strings[0], x) && detail::lexical_cast(str1, y);
2090 output = ConvertTo{x, y};
2094 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
2099template <
class AssignTo,
2101 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
2102 (type_count<ConvertTo>::value == 1),
2103 detail::enabler> = detail::dummy>
2104bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2107 output.reserve(strings.size());
2108 for(
const auto &elem : strings) {
2110 output.emplace_back();
2111 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
2113 return (!output.empty()) && retval;
2119template <
class AssignTo,
2121 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
2122 type_count_base<ConvertTo>::value == 2,
2123 detail::enabler> = detail::dummy>
2124bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
2127template <
class AssignTo,
2129 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
2130 type_count_base<ConvertTo>::value != 2 &&
2131 ((type_count<ConvertTo>::value > 2) ||
2132 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
2133 detail::enabler> = detail::dummy>
2134bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
2137template <
class AssignTo,
2139 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
2140 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
2141 type_count<ConvertTo>::value > 2),
2142 detail::enabler> = detail::dummy>
2143bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
2147template <
typename AssignTo,
2149 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
2150 classify_object<ConvertTo>::value != object_category::wrapper_value &&
2151 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
2152 detail::enabler> = detail::dummy>
2153bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2155 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
2157 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
2158 output = AssignTo{val};
2161 output = AssignTo{};
2166template <
class AssignTo,
class ConvertTo, std::
size_t I>
2167inline typename std::enable_if<(
I >= type_count_base<AssignTo>::value),
bool>::type
2168tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
2173template <
class AssignTo,
class ConvertTo>
2174inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
2175tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
2176 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
2177 strings.erase(strings.begin());
2182template <
class AssignTo,
class ConvertTo>
2183inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
2184 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
2186tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
2187 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
2188 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
2193template <
class AssignTo,
class ConvertTo>
2194inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
2195 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
2197tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
2199 std::size_t index{subtype_count_min<ConvertTo>::value};
2200 const std::size_t mx_count{subtype_count<ConvertTo>::value};
2201 const std::size_t mx{(std::max)(mx_count, strings.size())};
2209 bool retval = lexical_conversion<AssignTo, ConvertTo>(
2210 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
2211 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
2216template <
class AssignTo,
class ConvertTo, std::
size_t I>
2217inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
2218tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
2220 using ConvertToElement =
typename std::
2221 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
2222 if(!strings.empty()) {
2223 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
2224 strings, std::get<I>(output));
2226 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
2231template <
class AssignTo,
2233 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
2234 type_count_base<ConvertTo>::value == 2,
2236bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
2238 while(!strings.empty()) {
2240 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1;
2241 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2;
2242 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
2243 if(!strings.empty()) {
2244 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
2247 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
2252 return (!output.empty());
2256template <
class AssignTo,
2258 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
2259 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
2260 type_count<ConvertTo>::value > 2),
2262bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2264 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
2265 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
2266 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
2270template <
class AssignTo,
2272 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
2273 type_count_base<ConvertTo>::value != 2 &&
2274 ((type_count<ConvertTo>::value > 2) ||
2275 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
2277bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
2280 std::vector<std::string> temp;
2282 std::size_t icount{0};
2283 std::size_t xcm{type_count<ConvertTo>::value};
2284 auto ii_max = strings.size();
2285 while(ii < ii_max) {
2286 temp.push_back(strings[ii]);
2289 if(icount == xcm ||
is_separator(temp.back()) || ii == ii_max) {
2290 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value &&
is_separator(temp.back())) {
2293 typename AssignTo::value_type temp_out;
2295 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
2300 output.insert(output.end(), std::move(temp_out));
2308template <
typename AssignTo,
2310 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
2311 std::is_assignable<ConvertTo &, ConvertTo>::value,
2312 detail::enabler> = detail::dummy>
2313bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
2314 if(strings.empty() || strings.front().empty()) {
2315 output = ConvertTo{};
2318 typename ConvertTo::value_type val;
2319 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
2320 output = ConvertTo{val};
2327template <
typename AssignTo,
2329 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
2330 !std::is_assignable<AssignTo &, ConvertTo>::value,
2331 detail::enabler> = detail::dummy>
2332bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
2333 using ConvertType =
typename ConvertTo::value_type;
2334 if(strings.empty() || strings.front().empty()) {
2335 output = ConvertType{};
2339 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
2351template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
2352void sum_flag_vector(
const std::vector<std::string> &flags, T &output) {
2353 std::int64_t count{0};
2354 for(
auto &flag : flags) {
2355 count += detail::to_flag_value(flag);
2357 output = (count > 0) ?
static_cast<T
>(count) : T{0};
2365template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
2366void sum_flag_vector(
const std::vector<std::string> &flags, T &output) {
2367 std::int64_t count{0};
2368 for(
auto &flag : flags) {
2369 count += detail::to_flag_value(flag);
2371 output =
static_cast<T
>(count);
2375#pragma warning(push)
2376#pragma warning(disable : 4800)
2386template <
typename T,
2387 enable_if_t<!std::is_signed<T>::value && !std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
2388void sum_flag_vector(
const std::vector<std::string> &flags, T &output) {
2389 std::int64_t count{0};
2390 for(
auto &flag : flags) {
2391 count += detail::to_flag_value(flag);
2393 std::string out = detail::to_string(count);
2408inline bool split_short(
const std::string ¤t, std::string &name, std::string &rest) {
2409 if(current.size() > 1 && current[0] ==
'-' &&
valid_first_char(current[1])) {
2410 name = current.substr(1, 1);
2411 rest = current.substr(2);
2418inline bool split_long(
const std::string ¤t, std::string &name, std::string &value) {
2419 if(current.size() > 2 && current.substr(0, 2) ==
"--" &&
valid_first_char(current[2])) {
2420 auto loc = current.find_first_of(
'=');
2421 if(loc != std::string::npos) {
2422 name = current.substr(2, loc - 2);
2423 value = current.substr(loc + 1);
2425 name = current.substr(2);
2435 if(current.size() > 1 && current[0] ==
'/' &&
valid_first_char(current[1])) {
2436 auto loc = current.find_first_of(
':');
2437 if(loc != std::string::npos) {
2438 name = current.substr(1, loc - 1);
2439 value = current.substr(loc + 1);
2441 name = current.substr(1);
2451 std::vector<std::string> output;
2453 while((val = current.find(
",")) != std::string::npos) {
2454 output.push_back(
trim_copy(current.substr(0, val)));
2455 current = current.substr(val + 1);
2464 flags.erase(std::remove_if(flags.begin(),
2466 [](
const std::string &name) {
2467 return ((name.empty()) || (!(((name.find_first_of(
'{') != std::string::npos) &&
2468 (name.back() ==
'}')) ||
2469 (name[0] ==
'!'))));
2472 std::vector<std::pair<std::string, std::string>> output;
2473 output.reserve(flags.size());
2474 for(
auto &flag : flags) {
2475 auto def_start = flag.find_first_of(
'{');
2476 std::string defval =
"false";
2477 if((def_start != std::string::npos) && (flag.back() ==
'}')) {
2478 defval = flag.substr(def_start + 1);
2480 flag.erase(def_start, std::string::npos);
2482 flag.erase(0, flag.find_first_not_of(
"-!"));
2483 output.emplace_back(flag, defval);
2489inline std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>
2492 std::vector<std::string> short_names;
2493 std::vector<std::string> long_names;
2494 std::string pos_name;
2496 for(std::string name : input) {
2497 if(name.length() == 0) {
2500 if(name.length() > 1 && name[0] ==
'-' && name[1] !=
'-') {
2502 short_names.emplace_back(1, name[1]);
2504 throw BadNameString::OneCharName(name);
2505 }
else if(name.length() > 2 && name.substr(0, 2) ==
"--") {
2506 name = name.substr(2);
2508 long_names.push_back(name);
2510 throw BadNameString::BadLongName(name);
2511 }
else if(name ==
"-" || name ==
"--") {
2512 throw BadNameString::DashesOnly(name);
2514 if(pos_name.length() > 0)
2515 throw BadNameString::MultiPositionalNames(name);
2520 return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>(
2521 short_names, long_names, pos_name);
2533 std::vector<std::string> parents{};
2539 std::vector<std::string> inputs{};
2543 std::vector<std::string> tmp = parents;
2544 tmp.emplace_back(name);
2545 return detail::join(tmp,
".");
2552 std::vector<ConfigItem> items{};
2556 virtual std::string
to_config(
const App *,
bool,
bool, std::string)
const = 0;
2559 virtual std::vector<ConfigItem>
from_config(std::istream &)
const = 0;
2563 if(item.
inputs.size() == 1) {
2564 return item.
inputs.at(0);
2566 throw ConversionError::TooManyInputsFlag(item.
fullname());
2570 std::vector<ConfigItem>
from_file(
const std::string &name) {
2571 std::ifstream input{name};
2573 throw FileError::Missing(name);
2575 return from_config(input);
2586 char commentChar =
'#';
2588 char arrayStart =
'[';
2590 char arrayEnd =
']';
2592 char arraySeparator =
',';
2594 char valueDelimiter =
'=';
2596 char stringQuote =
'"';
2598 char characterQuote =
'\'';
2600 uint8_t maximumLayers{255};
2602 char parentSeparatorChar{
'.'};
2604 int16_t configIndex{-1};
2606 std::string configSection{};
2610 to_config(
const App * ,
bool default_also,
bool write_description, std::string prefix)
const override;
2612 std::vector<ConfigItem> from_config(std::istream &input)
const override;
2615 commentChar = cchar;
2620 arrayStart = aStart;
2626 arraySeparator = aSep;
2631 valueDelimiter = vSep;
2636 stringQuote = qString;
2637 characterQuote = qChar;
2642 maximumLayers = layers;
2647 parentSeparatorChar =
sep;
2653 const std::string &
section()
const {
return configSection; }
2656 configSection = sectionName;
2663 int16_t
index()
const {
return configIndex; }
2666 configIndex = sectionIndex;
2682 arraySeparator =
' ';
2683 valueDelimiter =
'=';
2704 std::function<std::string()> desc_function_{[]() {
return std::string{}; }};
2708 std::function<std::string(std::string &)> func_{[](std::string &) {
return std::string{}; }};
2710 std::string name_{};
2712 int application_index_ = -1;
2716 bool non_modifying_{
false};
2721 explicit Validator(std::string validator_desc) : desc_function_([validator_desc]() {
return validator_desc; }) {}
2723 Validator(std::function<std::string(std::string &)> op, std::string validator_desc, std::string validator_name =
"")
2724 : desc_function_([validator_desc]() {
return validator_desc; }), func_(std::move(op)),
2725 name_(std::move(validator_name)) {}
2728 func_ = std::move(op);
2734 std::string retstring;
2736 if(non_modifying_) {
2737 std::string value = str;
2738 retstring = func_(value);
2740 retstring = func_(str);
2749 std::string value = str;
2750 return (active_) ? func_(value) : std::string{};
2755 desc_function_ = [validator_desc]() {
return validator_desc; };
2761 newval.
desc_function_ = [validator_desc]() {
return validator_desc; };
2767 return desc_function_();
2769 return std::string{};
2773 name_ = std::move(validator_name);
2779 newval.
name_ = std::move(validator_name);
2786 active_ = active_val;
2798 non_modifying_ = no_modify;
2803 application_index_ = app_index;
2825 newval._merge_description(*
this, other,
" AND ");
2828 const std::function<std::string(std::string & filename)> &f1 = func_;
2829 const std::function<std::string(std::string & filename)> &f2 = other.
func_;
2831 newval.
func_ = [f1, f2](std::string &input) {
2832 std::string s1 = f1(input);
2833 std::string s2 = f2(input);
2834 if(!s1.empty() && !s2.empty())
2835 return std::string(
"(") + s1 +
") AND (" + s2 +
")";
2850 newval._merge_description(*
this, other,
" OR ");
2853 const std::function<std::string(std::string &)> &f1 = func_;
2854 const std::function<std::string(std::string &)> &f2 = other.
func_;
2856 newval.
func_ = [f1, f2](std::string &input) {
2857 std::string s1 = f1(input);
2858 std::string s2 = f2(input);
2859 if(s1.empty() || s2.empty())
2860 return std::string();
2862 return std::string(
"(") + s1 +
") OR (" + s2 +
")";
2872 const std::function<std::string()> &dfunc1 = desc_function_;
2874 auto str = dfunc1();
2875 return (!str.empty()) ? std::string(
"NOT ") + str : std::string{};
2878 const std::function<std::string(std::string & res)> &f1 = func_;
2880 newval.
func_ = [f1, dfunc1](std::string &test) -> std::string {
2881 std::string s1 = f1(test);
2883 return std::string(
"check ") + dfunc1() +
" succeeded improperly";
2885 return std::string{};
2893 void _merge_description(
const Validator &val1,
const Validator &val2,
const std::string &merger) {
2895 const std::function<std::string()> &dfunc1 = val1.
desc_function_;
2896 const std::function<std::string()> &dfunc2 = val2.
desc_function_;
2898 desc_function_ = [=]() {
2899 std::string f1 = dfunc1();
2900 std::string f2 = dfunc2();
2901 if((f1.empty()) || (f2.empty())) {
2904 return std::string(1,
'(') + f1 +
')' + merger +
'(' + f2 +
')';
2921#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
2923inline path_type check_path(
const char *file)
noexcept {
2925 auto stat = std::filesystem::status(file, ec);
2927 return path_type::nonexistent;
2929 switch(stat.type()) {
2930 case std::filesystem::file_type::none:
2931 case std::filesystem::file_type::not_found:
2932 return path_type::nonexistent;
2933 case std::filesystem::file_type::directory:
2934 return path_type::directory;
2935 case std::filesystem::file_type::symlink:
2936 case std::filesystem::file_type::block:
2937 case std::filesystem::file_type::character:
2938 case std::filesystem::file_type::fifo:
2939 case std::filesystem::file_type::socket:
2940 case std::filesystem::file_type::regular:
2941 case std::filesystem::file_type::unknown:
2943 return path_type::file;
2949#if defined(_MSC_VER)
2950 struct __stat64 buffer;
2951 if(_stat64(
file, &buffer) == 0) {
2952 return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file;
2956 if(stat(
file, &buffer) == 0) {
2957 return ((buffer.st_mode & S_IFDIR) != 0) ? path_type::directory : path_type::file;
2960 return path_type::nonexistent;
2967 func_ = [](std::string &filename) {
2968 auto path_result =
check_path(filename.c_str());
2969 if(path_result == path_type::nonexistent) {
2970 return "File does not exist: " + filename;
2972 if(path_result == path_type::directory) {
2973 return "File is actually a directory: " + filename;
2975 return std::string();
2984 func_ = [](std::string &filename) {
2985 auto path_result =
check_path(filename.c_str());
2986 if(path_result == path_type::nonexistent) {
2987 return "Directory does not exist: " + filename;
2989 if(path_result == path_type::file) {
2990 return "Directory is actually a file: " + filename;
2992 return std::string();
3001 func_ = [](std::string &filename) {
3002 auto path_result =
check_path(filename.c_str());
3003 if(path_result == path_type::nonexistent) {
3004 return "Path does not exist: " + filename;
3006 return std::string();
3015 func_ = [](std::string &filename) {
3016 auto path_result =
check_path(filename.c_str());
3017 if(path_result != path_type::nonexistent) {
3018 return "Path already exists: " + filename;
3020 return std::string();
3029 func_ = [](std::string &ip_addr) {
3031 if(result.size() != 4) {
3032 return std::string(
"Invalid IPV4 address must have four parts (") + ip_addr +
')';
3035 for(
const auto &var : result) {
3036 bool retval = detail::lexical_cast(var, num);
3038 return std::string(
"Failed parsing number (") + var +
')';
3040 if(num < 0 || num > 255) {
3041 return std::string(
"Each IP number must be between 0 and 255 ") + var;
3044 return std::string();
3072 func_ = [](std::string &input_string) {
3073 auto val = DesiredType();
3074 if(!detail::lexical_cast(input_string, val)) {
3075 return std::string(
"Failed parsing ") + input_string +
" as a " + detail::type_name<DesiredType>();
3077 return std::string();
3093 template <
typename T>
3094 Range(T min_val, T max_val,
const std::string &validator_name = std::string{}) :
Validator(validator_name) {
3095 if(validator_name.empty()) {
3096 std::stringstream out;
3097 out << detail::type_name<T>() <<
" in [" << min_val <<
" - " << max_val <<
"]";
3098 description(out.str());
3101 func_ = [min_val, max_val](std::string &input) {
3103 bool converted = detail::lexical_cast(input, val);
3104 if((!converted) || (val < min_val || val > max_val))
3105 return std::string(
"Value ") + input +
" not in range " + std::to_string(min_val) +
" to " +
3106 std::to_string(max_val);
3108 return std::string{};
3113 template <
typename T>
3114 explicit Range(T max_val,
const std::string &validator_name = std::string{})
3115 :
Range(static_cast<T>(0), max_val, validator_name) {}
3122const Range PositiveNumber((std::numeric_limits<double>::min)(), (std::numeric_limits<double>::max)(),
"POSITIVE");
3131 template <
typename T>
Bound(T min_val, T max_val) {
3132 std::stringstream out;
3133 out << detail::type_name<T>() <<
" bounded to [" << min_val <<
" - " << max_val <<
"]";
3134 description(out.str());
3136 func_ = [min_val, max_val](std::string &input) {
3138 bool converted = detail::lexical_cast(input, val);
3140 return std::string(
"Value ") + input +
" could not be converted";
3143 input = detail::to_string(min_val);
3144 else if(val > max_val)
3145 input = detail::to_string(max_val);
3147 return std::string{};
3152 template <
typename T>
explicit Bound(T max_val) :
Bound(static_cast<T>(0), max_val) {}
3156template <
typename T,
3157 enable_if_t<is_copyable_ptr<typename std::remove_reference<T>::type>::value, detail::enabler> = detail::dummy>
3172 std::string out(1,
'{');
3173 out.append(detail::join(
3174 detail::smart_deref(set),
3182template <
typename T> std::string
generate_map(
const T &map,
bool key_only =
false) {
3185 std::string out(1,
'{');
3186 out.append(detail::join(
3187 detail::smart_deref(map),
3188 [key_only](
const iteration_type_t &v) {
3203 template <
typename CC,
typename VV>
3204 static auto test(
int) ->
decltype(std::declval<CC>().find(std::declval<VV>()), std::true_type());
3205 template <
typename,
typename>
static auto test(...) ->
decltype(std::false_type());
3207 static const auto value =
decltype(test<C, V>(0))::value;
3208 using type = std::integral_constant<bool, value>;
3212template <typename T, typename V, enable_if_t<!has_find<T, V>::value,
detail::enabler> = detail::dummy>
3213auto search(
const T &set,
const V &val) -> std::pair<bool,
decltype(std::begin(detail::smart_deref(set)))> {
3215 auto &setref = detail::smart_deref(set);
3216 auto it = std::find_if(std::begin(setref), std::end(setref), [&val](
decltype(*std::begin(setref)) v) {
3219 return {(it != std::end(setref)), it};
3223template <typename T, typename V, enable_if_t<has_find<T, V>::value,
detail::enabler> = detail::dummy>
3224auto search(
const T &set,
const V &val) -> std::pair<bool,
decltype(std::begin(detail::smart_deref(set)))> {
3225 auto &setref = detail::smart_deref(set);
3226 auto it = setref.find(val);
3227 return {(it != std::end(setref)), it};
3231template <
typename T,
typename V>
3232auto search(
const T &set,
const V &val,
const std::function<V(V)> &filter_function)
3233 -> std::pair<bool,
decltype(std::begin(detail::smart_deref(set)))> {
3236 auto res =
search(set, val);
3237 if((res.first) || (!(filter_function))) {
3241 auto &setref = detail::smart_deref(set);
3242 auto it = std::find_if(std::begin(setref), std::end(setref), [&](
decltype(*std::begin(setref)) v) {
3244 a = filter_function(a);
3247 return {(it != std::end(setref)), it};
3254template <
typename T>
3255inline typename std::enable_if<std::is_signed<T>::value, T>::type
overflowCheck(
const T &a,
const T &b) {
3256 if((a > 0) == (b > 0)) {
3257 return ((std::numeric_limits<T>::max)() / (std::abs)(a) < (std::abs)(b));
3259 return ((std::numeric_limits<T>::min)() / (std::abs)(a) > -(std::abs)(b));
3263template <
typename T>
3264inline typename std::enable_if<!std::is_signed<T>::value, T>::type
overflowCheck(
const T &a,
const T &b) {
3265 return ((std::numeric_limits<T>::max)() / a < b);
3269template <
typename T>
typename std::enable_if<std::is_integral<T>::value,
bool>::type
checked_multiply(T &a, T b) {
3270 if(a == 0 || b == 0 || a == 1 || b == 1) {
3274 if(a == (std::numeric_limits<T>::min)() || b == (std::numeric_limits<T>::min)()) {
3285template <
typename T>
3286typename std::enable_if<std::is_floating_point<T>::value,
bool>::type
checked_multiply(T &a, T b) {
3288 if(std::isinf(c) && !std::isinf(a) && !std::isinf(b)) {
3302 template <
typename T,
typename... Args>
3303 IsMember(std::initializer_list<T> values, Args &&...args)
3304 :
IsMember(std::vector<T>(values), std::forward<Args>(args)...) {}
3311 template <
typename T,
typename F>
explicit IsMember(T set, F filter_function) {
3322 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
3325 desc_function_ = [set]() {
return detail::generate_set(detail::smart_deref(set)); };
3329 func_ = [set, filter_fn](std::string &input) {
3331 if(!detail::lexical_cast(input, b)) {
3337 auto res = detail::search(set, b, filter_fn);
3345 return std::string{};
3349 return input +
" not in " + detail::generate_set(detail::smart_deref(set));
3354 template <
typename T,
typename... Args>
3357 std::forward<T>(set),
3358 [filter_fn_1, filter_fn_2](std::string a) {
return filter_fn_2(filter_fn_1(a)); },
3371 template <
typename... Args>
3372 Transformer(std::initializer_list<std::pair<std::string, std::string>> values, Args &&...args)
3380 template <
typename T,
typename F>
explicit Transformer(T mapping, F filter_function) {
3383 "mapping must produce value pairs");
3392 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
3395 desc_function_ = [mapping]() {
return detail::generate_map(detail::smart_deref(mapping)); };
3397 func_ = [mapping, filter_fn](std::string &input) {
3399 if(!detail::lexical_cast(input, b)) {
3400 return std::string();
3406 auto res = detail::search(mapping, b, filter_fn);
3410 return std::string{};
3415 template <
typename T,
typename... Args>
3418 std::forward<T>(mapping),
3419 [filter_fn_1, filter_fn_2](std::string a) {
return filter_fn_2(filter_fn_1(a)); },
3429 template <
typename... Args>
3441 "mapping must produce value pairs");
3451 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
3453 auto tfunc = [mapping]() {
3454 std::string out(
"value in ");
3455 out += detail::generate_map(detail::smart_deref(mapping)) +
" OR {";
3456 out += detail::join(
3457 detail::smart_deref(mapping),
3464 desc_function_ = tfunc;
3466 func_ = [mapping, tfunc, filter_fn](std::string &input) {
3468 bool converted = detail::lexical_cast(input, b);
3473 auto res = detail::search(mapping, b, filter_fn);
3476 return std::string{};
3479 for(
const auto &v : detail::smart_deref(mapping)) {
3481 if(output_string == input) {
3482 return std::string();
3486 return "Check " + input +
" " + tfunc() +
" FAILED";
3491 template <
typename T,
typename... Args>
3494 std::forward<T>(mapping),
3495 [filter_fn_1, filter_fn_2](std::string a) {
return filter_fn_2(filter_fn_1(a)); },
3500inline std::string
ignore_case(std::string item) {
return detail::to_lower(item); }
3507 item.erase(std::remove(std::begin(item), std::end(item),
' '), std::end(item));
3508 item.erase(std::remove(std::begin(item), std::end(item),
'\t'), std::end(item));
3531 CASE_INSENSITIVE = 1,
3534 DEFAULT = CASE_INSENSITIVE | UNIT_OPTIONAL
3537 template <
typename Number>
3540 const std::string &unit_name =
"UNIT") {
3541 description(generate_description<Number>(unit_name, opts));
3542 validate_mapping(mapping, opts);
3545 func_ = [mapping, opts](std::string &input) -> std::string {
3548 detail::rtrim(input);
3554 auto unit_begin = input.end();
3555 while(unit_begin > input.begin() && std::isalpha(*(unit_begin - 1), std::locale())) {
3559 std::string unit{unit_begin, input.end()};
3560 input.resize(
static_cast<std::size_t
>(std::distance(input.begin(), unit_begin)));
3561 detail::trim(input);
3563 if(opts & UNIT_REQUIRED && unit.empty()) {
3566 if(opts & CASE_INSENSITIVE) {
3567 unit = detail::to_lower(unit);
3570 if(!detail::lexical_cast(input, num)) {
3571 throw ValidationError(std::string(
"Value ") + input +
" could not be converted to " +
3572 detail::type_name<Number>());
3579 auto it = mapping.find(unit);
3580 if(it == mapping.end()) {
3582 " unit not recognized. "
3583 "Allowed values: " +
3584 detail::generate_map(mapping,
true));
3587 if(!input.empty()) {
3588 bool converted = detail::lexical_cast(input, num);
3590 throw ValidationError(std::string(
"Value ") + input +
" could not be converted to " +
3591 detail::type_name<Number>());
3594 bool ok = detail::checked_multiply(num, it->second);
3596 throw ValidationError(detail::to_string(num) +
" multiplied by " + unit +
3597 " factor would cause number overflow. Use smaller value.");
3600 num =
static_cast<Number>(it->second);
3603 input = detail::to_string(num);
3612 template <
typename Number>
static void validate_mapping(std::map<std::string, Number> &mapping, Options opts) {
3613 for(
auto &kv : mapping) {
3614 if(kv.first.empty()) {
3617 if(!detail::isalpha(kv.first)) {
3618 throw ValidationError(
"Unit must contain only letters.");
3623 if(opts & CASE_INSENSITIVE) {
3624 std::map<std::string, Number> lower_mapping;
3625 for(
auto &kv : mapping) {
3626 auto s = detail::to_lower(kv.first);
3627 if(lower_mapping.count(s)) {
3628 throw ValidationError(std::string(
"Several matching lowercase unit representations are found: ") +
3631 lower_mapping[detail::to_lower(kv.first)] = kv.second;
3633 mapping = std::move(lower_mapping);
3638 template <
typename Number>
static std::string generate_description(
const std::string &name, Options opts) {
3639 std::stringstream out;
3640 out << detail::type_name<Number>() <<
' ';
3641 if(opts & UNIT_REQUIRED) {
3644 out <<
'[' << name <<
']';
3674 description(
"SIZE [b, kb(=1000b), kib(=1024b), ...]");
3676 description(
"SIZE [b, kb(=1024b), ...]");
3682 static std::map<std::string, result_t> init_mapping(
bool kb_is_1000) {
3683 std::map<std::string, result_t> m;
3684 result_t k_factor = kb_is_1000 ? 1000 : 1024;
3685 result_t ki_factor = 1024;
3689 for(std::string p : {
"k",
"m",
"g",
"t",
"p",
"e"}) {
3701 static std::map<std::string, result_t> get_mapping(
bool kb_is_1000) {
3703 static auto m = init_mapping(
true);
3706 static auto m = init_mapping(
false);
3719 std::pair<std::string, std::string> vals;
3721 auto esp = commandline.find_first_of(
' ', 1);
3722 while(detail::check_path(commandline.substr(0, esp).c_str()) != path_type::file) {
3723 esp = commandline.find_first_of(
' ', esp + 1);
3724 if(esp == std::string::npos) {
3727 if(commandline[0] ==
'"' || commandline[0] ==
'\'' || commandline[0] ==
'`') {
3728 bool embeddedQuote =
false;
3729 auto keyChar = commandline[0];
3730 auto end = commandline.find_first_of(keyChar, 1);
3731 while((end != std::string::npos) && (commandline[end - 1] ==
'\\')) {
3732 end = commandline.find_first_of(keyChar, end + 1);
3733 embeddedQuote =
true;
3735 if(end != std::string::npos) {
3736 vals.first = commandline.substr(1, end - 1);
3739 vals.first =
find_and_replace(vals.first, std::string(
"\\") + keyChar, std::string(1, keyChar));
3742 esp = commandline.find_first_of(
' ', 1);
3745 esp = commandline.find_first_of(
' ', 1);
3751 if(vals.first.empty()) {
3752 vals.first = commandline.substr(0, esp);
3757 vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{};
3792 std::size_t column_width_{30};
3796 std::map<std::string, std::string> labels_{};
3818 void label(std::string key, std::string val) { labels_[key] = val; }
3829 if(labels_.find(key) == labels_.end())
3832 return labels_.at(key);
3843 using funct_t = std::function<std::string(
const App *, std::string,
AppFormatMode)>;
3857 return lambda_(app, name, mode);
3874 virtual std::string make_group(std::string group,
bool is_positional, std::vector<const Option *> opts)
const;
3877 virtual std::string make_positionals(
const App *app)
const;
3883 virtual std::string make_subcommands(
const App *app,
AppFormatMode mode)
const;
3886 virtual std::string make_subcommand(
const App *sub)
const;
3889 virtual std::string make_expanded(
const App *sub)
const;
3892 virtual std::string make_footer(
const App *app)
const;
3895 virtual std::string make_description(
const App *app)
const;
3898 virtual std::string make_usage(
const App *app, std::string name)
const;
3901 std::string make_help(
const App * , std::string,
AppFormatMode)
const override;
3909 std::stringstream out;
3910 detail::format_help(
3911 out, make_option_name(opt, is_positional) + make_option_opts(opt), make_option_desc(opt), column_width_);
3916 virtual std::string make_option_name(
const Option *,
bool)
const;
3919 virtual std::string make_option_opts(
const Option *)
const;
3922 virtual std::string make_option_desc(
const Option *)
const;
3925 virtual std::string make_option_usage(
const Option *opt)
const;
3957 std::string group_ = std::string(
"Options");
3960 bool required_{
false};
3963 bool ignore_case_{
false};
3966 bool ignore_underscore_{
false};
3969 bool configurable_{
true};
3972 bool disable_flag_override_{
false};
3975 char delimiter_{
'\0'};
3978 bool always_capture_default_{
false};
3984 template <
typename T>
void copy_to(T *other)
const {
3985 other->group(group_);
3986 other->required(required_);
3987 other->ignore_case(ignore_case_);
3988 other->ignore_underscore(ignore_underscore_);
3989 other->configurable(configurable_);
3990 other->disable_flag_override(disable_flag_override_);
3991 other->delimiter(delimiter_);
3992 other->always_capture_default(always_capture_default_);
3993 other->multi_option_policy(multi_option_policy_);
4001 if(!detail::valid_alias_name_string(name)) {
4005 return static_cast<CRTP *
>(
this);
4011 return static_cast<CRTP *
>(
this);
4015 CRTP *
mandatory(
bool value =
true) {
return required(value); }
4018 always_capture_default_ = value;
4019 return static_cast<CRTP *
>(
this);
4055 auto self =
static_cast<CRTP *
>(
this);
4056 self->multi_option_policy(MultiOptionPolicy::TakeLast);
4062 auto self =
static_cast<CRTP *
>(
this);
4063 self->multi_option_policy(MultiOptionPolicy::TakeFirst);
4069 auto self =
static_cast<CRTP *
>(
this);
4070 self->multi_option_policy(MultiOptionPolicy::TakeAll);
4076 auto self =
static_cast<CRTP *
>(
this);
4077 self->multi_option_policy(MultiOptionPolicy::Join);
4083 auto self =
static_cast<CRTP *
>(
this);
4084 self->delimiter_ = delim;
4085 self->multi_option_policy(MultiOptionPolicy::Join);
4091 configurable_ = value;
4092 return static_cast<CRTP *
>(
this);
4098 return static_cast<CRTP *
>(
this);
4112 multi_option_policy_ = value;
4118 ignore_case_ = value;
4124 ignore_underscore_ = value;
4130 disable_flag_override_ = value;
4149 std::vector<std::string> snames_{};
4152 std::vector<std::string> lnames_{};
4156 std::vector<std::pair<std::string, std::string>> default_flag_values_{};
4159 std::vector<std::string> fnames_{};
4162 std::string pname_{};
4165 std::string envname_{};
4172 std::string description_{};
4175 std::string default_str_{};
4178 std::string option_text_{};
4183 std::function<std::string()> type_name_{[]() {
return std::string(); }};
4186 std::function<std::string()> default_function_{};
4194 int type_size_max_{1};
4196 int type_size_min_{1};
4199 int expected_min_{1};
4201 int expected_max_{1};
4204 std::vector<Validator> validators_{};
4207 std::set<Option *> needs_{};
4210 std::set<Option *> excludes_{};
4240 bool allow_extra_args_{
false};
4242 bool flag_like_{
false};
4244 bool run_callback_for_default_{
false};
4246 bool inject_separator_{
false};
4248 bool trigger_on_result_{
false};
4250 bool force_callback_{
false};
4255 : description_(std::move(option_description)), parent_(parent), callback_(std::move(callback)) {
4256 std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(option_name));
4267 std::size_t
count()
const {
return results_.size(); }
4270 bool empty()
const {
return results_.empty(); }
4273 explicit operator bool()
const {
return !empty() || force_callback_; }
4278 current_option_state_ = option_state::parsing;
4288 expected_min_ = -value;
4289 if(expected_max_ < expected_min_) {
4290 expected_max_ = expected_min_;
4292 allow_extra_args_ =
true;
4294 }
else if(value == detail::expected_max_vector_size) {
4296 expected_max_ = detail::expected_max_vector_size;
4297 allow_extra_args_ =
true;
4300 expected_min_ = value;
4301 expected_max_ = value;
4302 flag_like_ = (expected_min_ == 0);
4310 value_min = -value_min;
4314 value_max = detail::expected_max_vector_size;
4316 if(value_max < value_min) {
4317 expected_min_ = value_max;
4318 expected_max_ = value_min;
4320 expected_max_ = value_max;
4321 expected_min_ = value_min;
4329 allow_extra_args_ = value;
4336 trigger_on_result_ = value;
4344 force_callback_ = value;
4353 run_callback_for_default_ = value;
4362 validators_.push_back(std::move(validator));
4363 if(!validator_name.empty())
4364 validators_.back().
name(validator_name);
4370 std::string Validator_description =
"",
4371 std::string Validator_name =
"") {
4372 validators_.emplace_back(
Validator, std::move(Validator_description), std::move(Validator_name));
4373 validators_.back().non_modifying();
4379 validators_.insert(validators_.begin(), std::move(
Validator));
4380 if(!Validator_name.empty())
4381 validators_.front().name(Validator_name);
4387 std::string transform_description =
"",
4388 std::string transform_name =
"") {
4389 validators_.insert(validators_.begin(),
4391 [func](std::string &val) {
4393 return std::string{};
4395 std::move(transform_description),
4396 std::move(transform_name)));
4403 validators_.emplace_back(
4404 [func](std::string &inout) {
4406 return std::string{};
4418 if((Validator_name.empty()) && (!validators_.empty())) {
4419 return &(validators_.front());
4421 throw OptionNotFound(std::string{
"Validator "} + Validator_name +
" Not Found");
4427 if(index >= 0 && index <
static_cast<int>(validators_.size())) {
4428 return &(validators_[
static_cast<decltype(validators_)::size_type
>(index)]);
4443 auto opt =
static_cast<T *
>(parent_)->get_option_no_throw(opt_name);
4444 if(opt ==
nullptr) {
4445 throw IncorrectConstruction::MissingOption(opt_name);
4451 template <
typename A,
typename B,
typename... ARG>
Option *
needs(A opt, B opt1, ARG... args) {
4453 return needs(opt1, args...);
4458 auto iterator = std::find(std::begin(needs_), std::end(needs_), opt);
4460 if(iterator == std::end(needs_)) {
4463 needs_.erase(iterator);
4472 excludes_.insert(opt);
4485 auto opt =
static_cast<T *
>(parent_)->get_option_no_throw(opt_name);
4486 if(opt ==
nullptr) {
4487 throw IncorrectConstruction::MissingOption(opt_name);
4489 return excludes(opt);
4493 template <
typename A,
typename B,
typename... ARG>
Option *
excludes(A opt, B opt1, ARG... args) {
4495 return excludes(opt1, args...);
4500 auto iterator = std::find(std::begin(excludes_), std::end(excludes_), opt);
4502 if(iterator == std::end(excludes_)) {
4505 excludes_.erase(iterator);
4511 envname_ = std::move(name);
4520 if(!ignore_case_ && value) {
4521 ignore_case_ = value;
4522 auto *parent =
static_cast<T *
>(parent_);
4523 for(
const Option_p &opt : parent->options_) {
4524 if(opt.get() ==
this) {
4528 if(!omatch.empty()) {
4529 ignore_case_ =
false;
4530 throw OptionAlreadyAdded(
"adding ignore case caused a name conflict with " + omatch);
4534 ignore_case_ = value;
4545 if(!ignore_underscore_ && value) {
4546 ignore_underscore_ = value;
4547 auto *parent =
static_cast<T *
>(parent_);
4548 for(
const Option_p &opt : parent->options_) {
4549 if(opt.get() ==
this) {
4553 if(!omatch.empty()) {
4554 ignore_underscore_ =
false;
4555 throw OptionAlreadyAdded(
"adding ignore underscore caused a name conflict with " + omatch);
4559 ignore_underscore_ = value;
4566 if(value != multi_option_policy_) {
4567 if(multi_option_policy_ == MultiOptionPolicy::Throw && expected_max_ == detail::expected_max_vector_size &&
4568 expected_min_ > 1) {
4570 expected_max_ = expected_min_;
4572 multi_option_policy_ = value;
4573 current_option_state_ = option_state::parsing;
4580 disable_flag_override_ = value;
4614 const std::vector<std::string> &
get_lnames()
const {
return lnames_; }
4617 const std::vector<std::string> &
get_snames()
const {
return snames_; }
4620 const std::vector<std::string> &
get_fnames()
const {
return fnames_; }
4623 if(!lnames_.empty()) {
4626 if(!pname_.empty()) {
4629 if(!snames_.empty()) {
4647 int t = type_size_max_;
4648 return detail::checked_multiply(t, expected_max_) ? t : detail::expected_max_vector_size;
4667 description_ = std::move(option_description);
4672 option_text_ = std::move(text);
4687 bool all_options =
false
4689 if(get_group().empty())
4694 std::vector<std::string> name_list;
4697 if((positional && (!pname_.empty())) || (snames_.empty() && lnames_.empty())) {
4698 name_list.push_back(pname_);
4700 if((get_items_expected() == 0) && (!fnames_.empty())) {
4701 for(
const std::string &sname : snames_) {
4702 name_list.push_back(
"-" + sname);
4703 if(check_fname(sname)) {
4704 name_list.back() +=
"{" + get_flag_value(sname,
"") +
"}";
4708 for(
const std::string &lname : lnames_) {
4709 name_list.push_back(
"--" + lname);
4710 if(check_fname(lname)) {
4711 name_list.back() +=
"{" + get_flag_value(lname,
"") +
"}";
4715 for(
const std::string &sname : snames_)
4716 name_list.push_back(
"-" + sname);
4718 for(
const std::string &lname : lnames_)
4719 name_list.push_back(
"--" + lname);
4722 return detail::join(name_list);
4730 if(!lnames_.empty())
4731 return std::string(2,
'-') + lnames_[0];
4734 if(!snames_.empty())
4735 return std::string(1,
'-') + snames_[0];
4747 if(force_callback_ && results_.empty()) {
4748 add_result(default_str_);
4750 if(current_option_state_ == option_state::parsing) {
4751 _validate_results(results_);
4752 current_option_state_ = option_state::validated;
4755 if(current_option_state_ < option_state::reduced) {
4756 _reduce_results(proc_results_, results_);
4757 current_option_state_ = option_state::reduced;
4759 if(current_option_state_ >= option_state::reduced) {
4760 current_option_state_ = option_state::callback_run;
4764 const results_t &send_results = proc_results_.empty() ? results_ : proc_results_;
4765 bool local_result = callback_(send_results);
4774 static const std::string estring;
4775 for(
const std::string &sname : snames_)
4778 for(
const std::string &lname : lnames_)
4783 ignore_underscore_) {
4784 for(
const std::string &sname : other.
snames_)
4785 if(check_sname(sname))
4787 for(
const std::string &lname : other.
lnames_)
4788 if(check_lname(lname))
4799 if(name.length() > 2 && name[0] ==
'-' && name[1] ==
'-')
4800 return check_lname(name.substr(2));
4801 if(name.length() > 1 && name.front() ==
'-')
4802 return check_sname(name.substr(1));
4803 if(!pname_.empty()) {
4804 std::string local_pname = pname_;
4805 std::string local_name = name;
4806 if(ignore_underscore_) {
4807 local_pname = detail::remove_underscore(local_pname);
4808 local_name = detail::remove_underscore(local_name);
4811 local_pname = detail::to_lower(local_pname);
4812 local_name = detail::to_lower(local_name);
4814 if(local_name == local_pname) {
4819 if(!envname_.empty()) {
4821 return (name == envname_);
4828 return (detail::find_member(std::move(name), snames_, ignore_case_) >= 0);
4833 return (detail::find_member(std::move(name), lnames_, ignore_case_, ignore_underscore_) >= 0);
4838 if(fnames_.empty()) {
4841 return (detail::find_member(std::move(name), fnames_, ignore_case_, ignore_underscore_) >= 0);
4847 static const std::string trueString{
"true"};
4848 static const std::string falseString{
"false"};
4849 static const std::string emptyString{
"{}"};
4851 if(disable_flag_override_) {
4852 if(!((input_value.empty()) || (input_value == emptyString))) {
4853 auto default_ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
4854 if(default_ind >= 0) {
4856 if(default_flag_values_[
static_cast<std::size_t
>(default_ind)].second != input_value) {
4857 throw(ArgumentMismatch::FlagOverride(name));
4860 if(input_value != trueString) {
4861 throw(ArgumentMismatch::FlagOverride(name));
4866 auto ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
4867 if((input_value.empty()) || (input_value == emptyString)) {
4869 return (ind < 0) ? trueString : default_flag_values_[
static_cast<std::size_t
>(ind)].second;
4871 return (ind < 0) ? default_str_ : default_flag_values_[
static_cast<std::size_t
>(ind)].second;
4877 if(default_flag_values_[
static_cast<std::size_t
>(ind)].second == falseString) {
4879 auto val = detail::to_flag_value(input_value);
4880 return (val == 1) ? falseString : (val == (-1) ? trueString : std::to_string(-val));
4881 }
catch(
const std::invalid_argument &) {
4891 _add_result(std::move(s), results_);
4892 current_option_state_ = option_state::parsing;
4898 results_added = _add_result(std::move(s), results_);
4899 current_option_state_ = option_state::parsing;
4905 current_option_state_ = option_state::parsing;
4906 for(
auto &str : s) {
4907 _add_result(std::move(str), results_);
4917 results_t res = proc_results_.empty() ? results_ : proc_results_;
4918 if(current_option_state_ < option_state::reduced) {
4919 if(current_option_state_ == option_state::parsing) {
4921 _validate_results(res);
4925 _reduce_results(extra, res);
4926 if(!extra.empty()) {
4927 res = std::move(extra);
4935 template <
typename T>
void results(T &output)
const {
4937 if(current_option_state_ >= option_state::reduced || (results_.size() == 1 && validators_.empty())) {
4938 const results_t &res = (proc_results_.empty()) ? results_ : proc_results_;
4939 retval = detail::lexical_conversion<T, T>(res, output);
4942 if(results_.empty()) {
4943 if(!default_str_.empty()) {
4945 _add_result(std::string(default_str_), res);
4946 _validate_results(res);
4948 _reduce_results(extra, res);
4949 if(!extra.empty()) {
4950 res = std::move(extra);
4956 res = reduced_results();
4958 retval = detail::lexical_conversion<T, T>(res, output);
4966 template <
typename T> T
as()
const {
4973 bool get_callback_run()
const {
return (current_option_state_ == option_state::callback_run); }
4981 type_name_ = std::move(typefun);
4987 type_name_fn([typeval]() {
return typeval; });
4993 if(option_type_size < 0) {
4995 type_size_max_ = -option_type_size;
4996 type_size_min_ = -option_type_size;
4997 expected_max_ = detail::expected_max_vector_size;
4999 type_size_max_ = option_type_size;
5000 if(type_size_max_ < detail::expected_max_vector_size) {
5001 type_size_min_ = option_type_size;
5003 inject_separator_ =
true;
5005 if(type_size_max_ == 0)
5012 if(option_type_size_min < 0 || option_type_size_max < 0) {
5014 expected_max_ = detail::expected_max_vector_size;
5015 option_type_size_min = (std::abs)(option_type_size_min);
5016 option_type_size_max = (std::abs)(option_type_size_max);
5019 if(option_type_size_min > option_type_size_max) {
5020 type_size_max_ = option_type_size_min;
5021 type_size_min_ = option_type_size_max;
5023 type_size_min_ = option_type_size_min;
5024 type_size_max_ = option_type_size_max;
5026 if(type_size_max_ == 0) {
5029 if(type_size_max_ >= detail::expected_max_vector_size) {
5030 inject_separator_ =
true;
5040 default_function_ = func;
5046 if(default_function_) {
5047 default_str_ = default_function_();
5054 default_str_ = std::move(val);
5061 std::string val_str = detail::to_string(val);
5062 auto old_option_state = current_option_state_;
5063 results_t old_results{std::move(results_)};
5066 add_result(val_str);
5068 if(run_callback_for_default_ && !trigger_on_result_) {
5070 current_option_state_ = option_state::parsing;
5072 _validate_results(results_);
5073 current_option_state_ = old_option_state;
5077 results_ = std::move(old_results);
5078 current_option_state_ = old_option_state;
5081 results_ = std::move(old_results);
5082 default_str_ = std::move(val_str);
5088 std::string full_type_name = type_name_();
5089 if(!validators_.empty()) {
5092 if(!vtype.empty()) {
5093 full_type_name +=
":" + vtype;
5097 return full_type_name;
5102 void _validate_results(
results_t &res)
const {
5104 if(!validators_.empty()) {
5105 if(type_size_max_ > 1) {
5107 if(get_items_expected_max() <
static_cast<int>(res.size()) &&
5110 index = get_items_expected_max() -
static_cast<int>(res.size());
5113 for(std::string &result : res) {
5114 if(detail::is_separator(result) && type_size_max_ != type_size_min_ && index >= 0) {
5118 auto err_msg = _validate(result, (index >= 0) ? (index % type_size_max_) : index);
5119 if(!err_msg.empty())
5125 if(expected_max_ <
static_cast<int>(res.size()) &&
5128 index = expected_max_ -
static_cast<int>(res.size());
5130 for(std::string &result : res) {
5131 auto err_msg = _validate(result, index);
5133 if(!err_msg.empty())
5143 void _reduce_results(results_t &res,
const results_t &original)
const {
5150 switch(multi_option_policy_) {
5151 case MultiOptionPolicy::TakeAll:
5153 case MultiOptionPolicy::TakeLast: {
5155 std::size_t trim_size = std::min<std::size_t>(
5156 static_cast<std::size_t
>(std::max<int>(get_items_expected_max(), 1)), original.size());
5157 if(original.size() != trim_size) {
5158 res.assign(original.end() -
static_cast<results_t::difference_type
>(trim_size), original.end());
5161 case MultiOptionPolicy::TakeFirst: {
5162 std::size_t trim_size = std::min<std::size_t>(
5163 static_cast<std::size_t
>(std::max<int>(get_items_expected_max(), 1)), original.size());
5164 if(original.size() != trim_size) {
5165 res.assign(original.begin(), original.begin() +
static_cast<results_t::difference_type
>(trim_size));
5168 case MultiOptionPolicy::Join:
5169 if(results_.size() > 1) {
5170 res.push_back(detail::join(original, std::string(1, (delimiter_ ==
'\0') ?
'\n' : delimiter_)));
5173 case MultiOptionPolicy::Throw:
5175 auto num_min =
static_cast<std::size_t
>(get_items_expected_min());
5176 auto num_max =
static_cast<std::size_t
>(get_items_expected_max());
5183 if(original.size() < num_min) {
5184 throw ArgumentMismatch::AtLeast(get_name(),
static_cast<int>(num_min), original.size());
5186 if(original.size() > num_max) {
5187 throw ArgumentMismatch::AtMost(get_name(),
static_cast<int>(num_max), original.size());
5195 std::string _validate(std::string &result,
int index)
const {
5196 std::string err_msg;
5197 if(result.empty() && expected_min_ == 0) {
5201 for(
const auto &vali : validators_) {
5202 auto v = vali.get_application_index();
5203 if(v == -1 || v == index) {
5205 err_msg = vali(result);
5206 }
catch(
const ValidationError &err) {
5207 err_msg = err.what();
5209 if(!err_msg.empty())
5218 int _add_result(std::string &&result, std::vector<std::string> &res)
const {
5219 int result_count = 0;
5220 if(allow_extra_args_ && !result.empty() && result.front() ==
'[' &&
5221 result.back() ==
']') {
5224 for(
auto &var :
CLI::detail::
split(result.substr(1),
',')) {
5226 result_count += _add_result(std::move(var), res);
5229 return result_count;
5231 if(delimiter_ ==
'\0') {
5232 res.push_back(std::move(result));
5235 if((result.find_first_of(delimiter_) != std::string::npos)) {
5236 for(
const auto &var :
CLI::detail::
split(result, delimiter_)) {
5243 res.push_back(std::move(result));
5247 return result_count;
5255#define CLI11_PARSE(app, argc, argv) \
5257 (app).parse((argc), (argv)); \
5258 } catch(const CLI::ParseError &e) { \
5259 return (app).exit(e); \
5268namespace FailureMessage {
5297 std::string name_{};
5300 std::string description_{};
5303 bool allow_extras_{
false};
5310 bool prefix_command_{
false};
5313 bool has_automatic_name_{
false};
5316 bool required_{
false};
5319 bool disabled_{
false};
5322 bool pre_parse_called_{
false};
5326 bool immediate_callback_{
false};
5329 std::function<void(std::size_t)> pre_parse_callback_{};
5332 std::function<void()> parse_complete_callback_{};
5335 std::function<void()> final_callback_{};
5345 std::vector<Option_p> options_{};
5352 std::string footer_{};
5355 std::function<std::string()> footer_callback_{};
5370 std::function<std::string(
const App *,
const Error &e)> failure_message_{FailureMessage::simple};
5376 using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
5384 std::vector<Option *> parse_order_{};
5387 std::vector<App *> parsed_subcommands_{};
5390 std::set<App *> exclude_subcommands_{};
5394 std::set<Option *> exclude_options_{};
5398 std::set<App *> need_subcommands_{};
5402 std::set<Option *> need_options_{};
5409 std::vector<App_p> subcommands_{};
5412 bool ignore_case_{
false};
5415 bool ignore_underscore_{
false};
5418 bool fallthrough_{
false};
5421 bool allow_windows_style_options_{
5429 bool positionals_at_end_{
false};
5437 bool configurable_{
false};
5440 bool validate_positionals_{
false};
5444 bool silent_{
false};
5447 std::uint32_t parsed_{0U};
5450 std::size_t require_subcommand_min_{0};
5453 std::size_t require_subcommand_max_{0};
5456 std::size_t require_option_min_{0};
5459 std::size_t require_option_max_{0};
5465 std::string group_{
"Subcommands"};
5468 std::vector<std::string> aliases_{};
5483 App(std::string app_description, std::string app_name,
App *parent)
5484 : name_(std::move(app_name)), description_(std::move(app_description)), parent_(parent) {
5486 if(parent_ !=
nullptr) {
5487 if(parent_->help_ptr_ !=
nullptr)
5488 set_help_flag(parent_->help_ptr_->get_name(
false,
true), parent_->help_ptr_->get_description());
5489 if(parent_->help_all_ptr_ !=
nullptr)
5490 set_help_all_flag(parent_->help_all_ptr_->get_name(
false,
true),
5491 parent_->help_all_ptr_->get_description());
5494 option_defaults_ = parent_->option_defaults_;
5497 failure_message_ = parent_->failure_message_;
5498 allow_extras_ = parent_->allow_extras_;
5499 allow_config_extras_ = parent_->allow_config_extras_;
5500 prefix_command_ = parent_->prefix_command_;
5501 immediate_callback_ = parent_->immediate_callback_;
5502 ignore_case_ = parent_->ignore_case_;
5503 ignore_underscore_ = parent_->ignore_underscore_;
5504 fallthrough_ = parent_->fallthrough_;
5505 validate_positionals_ = parent_->validate_positionals_;
5506 configurable_ = parent_->configurable_;
5507 allow_windows_style_options_ = parent_->allow_windows_style_options_;
5508 group_ = parent_->group_;
5509 footer_ = parent_->footer_;
5510 formatter_ = parent_->formatter_;
5511 config_formatter_ = parent_->config_formatter_;
5512 require_subcommand_max_ = parent_->require_subcommand_max_;
5521 explicit App(std::string app_description =
"", std::string app_name =
"")
5522 :
App(app_description, app_name, nullptr) {
5523 set_help_flag(
"-h,--help",
"Print this help message and exit");
5539 if(immediate_callback_) {
5540 parse_complete_callback_ = std::move(app_callback);
5542 final_callback_ = std::move(app_callback);
5550 final_callback_ = std::move(app_callback);
5557 parse_complete_callback_ = std::move(pc_callback);
5564 pre_parse_callback_ = std::move(pp_callback);
5571 if(parent_ !=
nullptr) {
5574 auto &res = _compare_subcommand_names(*
this, *_get_fallthrough_parent());
5582 has_automatic_name_ =
false;
5588 if(app_name.empty() || !detail::valid_alias_name_string(app_name)) {
5591 if(parent_ !=
nullptr) {
5592 aliases_.push_back(app_name);
5593 auto &res = _compare_subcommand_names(*
this, *_get_fallthrough_parent());
5595 aliases_.pop_back();
5596 throw(
OptionAlreadyAdded(
"alias already matches an existing subcommand: " + app_name));
5599 aliases_.push_back(app_name);
5607 allow_extras_ = allow;
5613 required_ = require;
5619 disabled_ = disable;
5632 default_startup = startup_mode::disabled;
5634 default_startup = (default_startup == startup_mode::enabled) ? startup_mode::enabled : startup_mode::stable;
5643 default_startup = startup_mode::enabled;
5646 (default_startup == startup_mode::disabled) ? startup_mode::disabled : startup_mode::stable;
5653 immediate_callback_ = immediate;
5654 if(immediate_callback_) {
5655 if(final_callback_ && !(parse_complete_callback_)) {
5656 std::swap(final_callback_, parse_complete_callback_);
5658 }
else if(!(final_callback_) && parse_complete_callback_) {
5659 std::swap(final_callback_, parse_complete_callback_);
5666 validate_positionals_ = validate;
5673 allow_config_extras_ = config_extras_mode::capture;
5674 allow_extras_ =
true;
5676 allow_config_extras_ = config_extras_mode::error;
5683 allow_config_extras_ = mode;
5689 prefix_command_ = allow;
5695 if(value && !ignore_case_) {
5696 ignore_case_ =
true;
5697 auto *p = (parent_ !=
nullptr) ? _get_fallthrough_parent() :
this;
5698 auto &match = _compare_subcommand_names(*
this, *p);
5699 if(!match.empty()) {
5700 ignore_case_ =
false;
5701 throw OptionAlreadyAdded(
"ignore case would cause subcommand name conflicts: " + match);
5704 ignore_case_ = value;
5711 allow_windows_style_options_ = value;
5717 positionals_at_end_ = value;
5723 configurable_ = value;
5729 if(value && !ignore_underscore_) {
5730 ignore_underscore_ =
true;
5731 auto *p = (parent_ !=
nullptr) ? _get_fallthrough_parent() :
this;
5732 auto &match = _compare_subcommand_names(*
this, *p);
5733 if(!match.empty()) {
5734 ignore_underscore_ =
false;
5735 throw OptionAlreadyAdded(
"ignore underscore would cause subcommand name conflicts: " + match);
5738 ignore_underscore_ = value;
5750 formatter_ = std::make_shared<FormatterLambda>(fmt);
5756 config_formatter_ = fmt;
5786 std::string option_description =
"",
5787 bool defaulted =
false,
5788 std::function<std::string()> func = {}) {
5789 Option myopt{option_name, option_description, option_callback,
this};
5791 if(std::find_if(std::begin(options_), std::end(options_), [&myopt](
const Option_p &v) {
5793 }) == std::end(options_)) {
5794 options_.emplace_back();
5795 Option_p &option = options_.back();
5796 option.reset(
new Option(option_name, option_description, option_callback,
this));
5799 option->default_function(func);
5803 option->capture_default_str();
5806 option_defaults_.copy_to(option.get());
5809 if(!defaulted && option->get_always_capture_default())
5810 option->capture_default_str();
5812 return option.get();
5815 for(
auto &opt : options_) {
5816 auto &matchname = opt->matching_name(myopt);
5817 if(!matchname.empty()) {
5818 throw(
OptionAlreadyAdded(
"added option matched existing option name: " + matchname));
5826 template <
typename AssignTo,
5827 typename ConvertTo = AssignTo,
5828 enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
5831 std::string option_description =
"") {
5834 return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
5837 Option *opt = add_option(option_name, fun, option_description,
false, [&variable]() {
5838 return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
5840 opt->
type_name(detail::type_name<ConvertTo>());
5845 opt->
type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
5846 opt->
expected(detail::expected_count<ConvertTo>::value);
5852 template <typename AssignTo, enable_if_t<!std::is_const<AssignTo>::value,
detail::enabler> = detail::dummy>
5855 std::string option_description =
"") {
5858 return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
5861 Option *opt = add_option(option_name, fun, option_description,
false, []() {
return std::string{}; });
5862 opt->
type_name(detail::type_name<AssignTo>());
5864 opt->
expected(detail::expected_count<AssignTo>::value);
5870 template <
typename ArgType>
5872 const std::function<
void(
const ArgType &)> &func,
5873 std::string option_description =
"") {
5877 bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
5884 Option *opt = add_option(option_name, std::move(fun), option_description,
false);
5885 opt->
type_name(detail::type_name<ArgType>());
5887 opt->
expected(detail::expected_count<ArgType>::value);
5893 return add_option(option_name,
CLI::callback_t{}, std::string{},
false);
5897 template <
typename T,
5901 return add_option(option_name,
CLI::callback_t(), option_description,
false);
5907 if(help_ptr_ !=
nullptr) {
5908 remove_option(help_ptr_);
5909 help_ptr_ =
nullptr;
5913 if(!flag_name.empty()) {
5914 help_ptr_ = add_flag(flag_name, help_description);
5915 help_ptr_->configurable(
false);
5924 if(help_all_ptr_ !=
nullptr) {
5925 remove_option(help_all_ptr_);
5926 help_all_ptr_ =
nullptr;
5930 if(!help_name.empty()) {
5931 help_all_ptr_ = add_flag(help_name, help_description);
5932 help_all_ptr_->configurable(
false);
5935 return help_all_ptr_;
5940 const std::string &versionString =
"",
5941 const std::string &version_help =
"Display program version information and exit") {
5943 if(version_ptr_ !=
nullptr) {
5944 remove_option(version_ptr_);
5945 version_ptr_ =
nullptr;
5949 if(!flag_name.empty()) {
5950 version_ptr_ = add_flag_callback(
5951 flag_name, [versionString]() {
throw(
CLI::CallForVersion(versionString, 0)); }, version_help);
5952 version_ptr_->configurable(
false);
5955 return version_ptr_;
5959 std::function<std::string()> vfunc,
5960 const std::string &version_help =
"Display program version information and exit") {
5961 if(version_ptr_ !=
nullptr) {
5962 remove_option(version_ptr_);
5963 version_ptr_ =
nullptr;
5967 if(!flag_name.empty()) {
5968 version_ptr_ = add_flag_callback(
5970 version_ptr_->configurable(
false);
5973 return version_ptr_;
5978 Option *_add_flag_internal(std::string flag_name,
CLI::callback_t fun, std::string flag_description) {
5980 if(detail::has_default_flag_values(flag_name)) {
5982 auto flag_defaults = detail::get_default_flag_values(flag_name);
5983 detail::remove_default_flag_values(flag_name);
5984 opt = add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
5985 for(
const auto &fname : flag_defaults)
5986 opt->fnames_.push_back(fname.first);
5989 opt = add_option(std::move(flag_name), std::move(fun), std::move(flag_description),
false);
5993 auto pos_name = opt->
get_name(
true);
5995 throw IncorrectConstruction::PositionalFlag(pos_name);
6010 template <
typename T,
6014 return _add_flag_internal(flag_name,
CLI::callback_t(), flag_description);
6019 template <
typename T,
6024 std::string flag_description =
"") {
6028 detail::sum_flag_vector(res, flag_count);
6029 }
catch(
const std::invalid_argument &) {
6034 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
6035 ->multi_option_policy(MultiOptionPolicy::TakeAll);
6040 template <
typename T,
6043 !std::is_constructible<std::function<
void(
int)>, T>::value,
6047 std::string flag_description =
"") {
6052 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))->run_callback_for_default();
6056 template <
typename T,
6060 std::vector<T> &flag_results,
6061 std::string flag_description =
"") {
6064 for(
const auto &elem : res) {
6065 flag_results.emplace_back();
6066 retval &= detail::lexical_cast(elem, flag_results.back());
6070 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
6071 ->multi_option_policy(MultiOptionPolicy::TakeAll)
6072 ->run_callback_for_default();
6077 std::function<
void(
void)> function,
6078 std::string flag_description =
"") {
6081 bool trigger{
false};
6083 if(result && trigger) {
6088 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
6093 std::function<
void(std::int64_t)> function,
6094 std::string flag_description =
"") {
6097 std::int64_t flag_count = 0;
6098 detail::sum_flag_vector(res, flag_count);
6099 function(flag_count);
6102 return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
6103 ->multi_option_policy(MultiOptionPolicy::TakeAll);
6108 Option *add_flag(std::string flag_name,
6109 std::function<
void(std::int64_t)> function,
6110 std::string flag_description =
"") {
6111 return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
6117 std::string default_filename =
"",
6118 const std::string &help_message =
"Read an ini file",
6119 bool config_required =
false) {
6122 if(config_ptr_ !=
nullptr) {
6123 remove_option(config_ptr_);
6124 config_ptr_ =
nullptr;
6128 if(!option_name.empty()) {
6129 config_ptr_ = add_option(option_name, help_message);
6130 if(config_required) {
6131 config_ptr_->required();
6133 if(!default_filename.empty()) {
6134 config_ptr_->default_str(std::move(default_filename));
6136 config_ptr_->configurable(
false);
6146 op->remove_needs(opt);
6147 op->remove_excludes(opt);
6150 if(help_ptr_ == opt)
6151 help_ptr_ =
nullptr;
6152 if(help_all_ptr_ == opt)
6153 help_all_ptr_ =
nullptr;
6156 std::find_if(std::begin(options_), std::end(options_), [opt](
const Option_p &v) {
return v.get() == opt; });
6157 if(iterator != std::end(options_)) {
6158 options_.erase(iterator);
6165 template <
typename T = Option_group>
6167 if(!detail::valid_alias_name_string(group_name)) {
6170 auto option_group = std::make_shared<T>(std::move(group_description), group_name,
this);
6171 auto ptr = option_group.get();
6173 App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
6174 add_subcommand(std::move(app_ptr));
6184 if(!subcommand_name.empty() && !detail::valid_name_string(subcommand_name)) {
6185 if(!detail::valid_first_char(subcommand_name[0])) {
6187 "Subcommand name starts with invalid character, '!' and '-' are not allowed");
6189 for(
auto c : subcommand_name) {
6190 if(!detail::valid_later_char(c)) {
6192 "'), all characters are allowed except"
6193 "'=',':','{','}', and ' '");
6197 CLI::App_p subcom = std::shared_ptr<App>(
new App(std::move(subcommand_description), subcommand_name,
this));
6198 return add_subcommand(std::move(subcom));
6205 auto ckapp = (name_.empty() && parent_ !=
nullptr) ? _get_fallthrough_parent() :
this;
6206 auto &mstrg = _compare_subcommand_names(*subcom, *ckapp);
6207 if(!mstrg.empty()) {
6208 throw(
OptionAlreadyAdded(
"subcommand name or alias matches existing subcommand: " + mstrg));
6210 subcom->parent_ =
this;
6211 subcommands_.push_back(std::move(subcom));
6212 return subcommands_.back().get();
6218 for(
App_p &sub : subcommands_) {
6219 sub->remove_excludes(subcom);
6220 sub->remove_needs(subcom);
6223 auto iterator = std::find_if(
6224 std::begin(subcommands_), std::end(subcommands_), [subcom](
const App_p &v) {
return v.get() == subcom; });
6225 if(iterator != std::end(subcommands_)) {
6226 subcommands_.erase(iterator);
6234 if(subcom ==
nullptr)
6236 for(
const App_p &subcomptr : subcommands_)
6237 if(subcomptr.get() == subcom)
6238 return subcomptr.get();
6244 auto subc = _find_subcommand(subcom,
false,
false);
6252 auto uindex =
static_cast<unsigned>(index);
6253 if(uindex < subcommands_.size())
6254 return subcommands_[uindex].get();
6261 if(subcom ==
nullptr)
6263 for(
const App_p &subcomptr : subcommands_)
6264 if(subcomptr.get() == subcom)
6271 for(
const App_p &subcomptr : subcommands_)
6272 if(subcomptr->check_name(subcom))
6280 auto uindex =
static_cast<unsigned>(index);
6281 if(uindex < subcommands_.size())
6282 return subcommands_[uindex];
6289 for(
const App_p &app : subcommands_) {
6290 if(app->name_.empty() && app->group_ == group_name) {
6300 std::size_t
count()
const {
return parsed_; }
6306 for(
auto &opt : options_) {
6307 cnt += opt->
count();
6309 for(
auto &sub : subcommands_) {
6310 cnt += sub->count_all();
6312 if(!get_name().empty()) {
6320 group_ = group_name;
6326 require_subcommand_min_ = 1;
6327 require_subcommand_max_ = 0;
6336 require_subcommand_min_ = 0;
6337 require_subcommand_max_ =
static_cast<std::size_t
>(-value);
6339 require_subcommand_min_ =
static_cast<std::size_t
>(value);
6340 require_subcommand_max_ =
static_cast<std::size_t
>(value);
6348 require_subcommand_min_ = min;
6349 require_subcommand_max_ = max;
6355 require_option_min_ = 1;
6356 require_option_max_ = 0;
6365 require_option_min_ = 0;
6366 require_option_max_ =
static_cast<std::size_t
>(-value);
6368 require_option_min_ =
static_cast<std::size_t
>(value);
6369 require_option_max_ =
static_cast<std::size_t
>(value);
6377 require_option_min_ = min;
6378 require_option_max_ = max;
6385 fallthrough_ = value;
6391 explicit operator bool()
const {
return parsed_ > 0; }
6410 pre_parse_called_ =
false;
6413 parsed_subcommands_.clear();
6414 for(
const Option_p &opt : options_) {
6417 for(
const App_p &subc : subcommands_) {
6424 void parse(
int argc,
const char *
const *argv) {
6426 if(name_.empty() || has_automatic_name_) {
6427 has_automatic_name_ =
true;
6431 std::vector<std::string> args;
6432 args.reserve(
static_cast<std::size_t
>(argc) - 1);
6433 for(
int i = argc - 1; i > 0; i--)
6434 args.emplace_back(argv[i]);
6435 parse(std::move(args));
6442 void parse(std::string commandline,
bool program_name_included =
false) {
6444 if(program_name_included) {
6445 auto nstr = detail::split_program_name(commandline);
6446 if((name_.empty()) || (has_automatic_name_)) {
6447 has_automatic_name_ =
true;
6450 commandline = std::move(nstr.second);
6452 detail::trim(commandline);
6455 if(!commandline.empty()) {
6456 commandline = detail::find_and_modify(commandline,
"=", detail::escape_detect);
6457 if(allow_windows_style_options_)
6458 commandline = detail::find_and_modify(commandline,
":", detail::escape_detect);
6461 auto args = detail::split_up(std::move(commandline));
6463 args.erase(std::remove(args.begin(), args.end(), std::string{}), args.end());
6464 std::reverse(args.begin(), args.end());
6466 parse(std::move(args));
6471 void parse(std::vector<std::string> &args) {
6491 void parse(std::vector<std::string> &&args) {
6506 _parse(std::move(args));
6517 _parse_stream(input);
6522 failure_message_ = function;
6526 int exit(
const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr)
const {
6532 if(e.
get_name() ==
"CallForHelp") {
6537 if(e.
get_name() ==
"CallForAllHelp") {
6538 out << help(
"", AppFormatMode::All);
6542 if(e.
get_name() ==
"CallForVersion") {
6543 out << e.what() << std::endl;
6547 if(e.
get_exit_code() !=
static_cast<int>(ExitCodes::Success)) {
6548 if(failure_message_)
6549 err << failure_message_(
this, e) << std::flush;
6560 std::size_t
count(std::string option_name)
const {
return get_option(option_name)->count(); }
6569 std::vector<const App *> subcomms(subcommands_.size());
6570 std::transform(std::begin(subcommands_), std::end(subcommands_), std::begin(subcomms), [](
const App_p &v) {
6575 subcomms.erase(std::remove_if(std::begin(subcomms),
6577 [&filter](
const App *app) {
return !filter(app); }),
6578 std::end(subcomms));
6587 std::vector<App *> subcomms(subcommands_.size());
6588 std::transform(std::begin(subcommands_), std::end(subcommands_), std::begin(subcomms), [](
const App_p &v) {
6594 std::remove_if(std::begin(subcomms), std::end(subcomms), [&filter](
App *app) {
return !filter(app); }),
6595 std::end(subcomms));
6604 return get_subcommand(subcom)->parsed_ > 0;
6608 bool got_subcommand(std::string subcommand_name)
const {
return get_subcommand(subcommand_name)->parsed_ > 0; }
6612 if(opt ==
nullptr) {
6615 exclude_options_.insert(opt);
6621 if(app ==
nullptr) {
6627 auto res = exclude_subcommands_.insert(app);
6636 if(opt ==
nullptr) {
6639 need_options_.insert(opt);
6644 if(app ==
nullptr) {
6650 need_subcommands_.insert(app);
6656 auto iterator = std::find(std::begin(exclude_options_), std::end(exclude_options_), opt);
6657 if(iterator == std::end(exclude_options_)) {
6660 exclude_options_.erase(iterator);
6666 auto iterator = std::find(std::begin(exclude_subcommands_), std::end(exclude_subcommands_), app);
6667 if(iterator == std::end(exclude_subcommands_)) {
6670 auto other_app = *iterator;
6671 exclude_subcommands_.erase(iterator);
6672 other_app->remove_excludes(
this);
6678 auto iterator = std::find(std::begin(need_options_), std::end(need_options_), opt);
6679 if(iterator == std::end(need_options_)) {
6682 need_options_.erase(iterator);
6688 auto iterator = std::find(std::begin(need_subcommands_), std::end(need_subcommands_), app);
6689 if(iterator == std::end(need_subcommands_)) {
6692 need_subcommands_.erase(iterator);
6702 footer_ = std::move(footer_string);
6707 footer_callback_ = std::move(footer_function);
6712 std::string
config_to_str(
bool default_also =
false,
bool write_description =
false)
const {
6713 return config_formatter_->to_config(
this, default_also, write_description,
"");
6722 prev +=
" " + get_name();
6725 auto selected_subcommands = get_subcommands();
6726 if(!selected_subcommands.empty()) {
6727 return selected_subcommands.at(0)->help(prev, mode);
6729 return formatter_->make_help(
this, prev, mode);
6735 if(version_ptr_ !=
nullptr) {
6736 auto rv = version_ptr_->results();
6737 version_ptr_->clear();
6738 version_ptr_->add_result(
"true");
6740 version_ptr_->run_callback();
6744 version_ptr_->clear();
6745 version_ptr_->add_result(rv);
6762#if defined(__cpp_rtti) || (defined(__GXX_RTTI) && __GXX_RTTI) || (defined(_HAS_STATIC_RTTI) && (_HAS_STATIC_RTTI == 0))
6763 return std::dynamic_pointer_cast<ConfigBase>(config_formatter_);
6765 return std::static_pointer_cast<ConfigBase>(config_formatter_);
6774 description_ = std::move(app_description);
6779 std::vector<const Option *>
get_options(
const std::function<
bool(
const Option *)> filter = {})
const {
6780 std::vector<const Option *> options(options_.size());
6781 std::transform(std::begin(options_), std::end(options_), std::begin(options), [](
const Option_p &val) {
6786 options.erase(std::remove_if(std::begin(options),
6788 [&filter](
const Option *opt) {
return !filter(opt); }),
6797 std::vector<Option *> options(options_.size());
6798 std::transform(std::begin(options_), std::end(options_), std::begin(options), [](
const Option_p &val) {
6804 std::remove_if(std::begin(options), std::end(options), [&filter](Option *opt) {
return !filter(opt); }),
6818 for(
auto &subc : subcommands_) {
6820 if(subc->get_name().empty()) {
6821 auto opt = subc->get_option_no_throw(option_name);
6822 if(opt !=
nullptr) {
6832 for(
const Option_p &opt : options_) {
6837 for(
const auto &subc : subcommands_) {
6839 if(subc->get_name().empty()) {
6840 auto opt = subc->get_option_no_throw(option_name);
6841 if(opt !=
nullptr) {
6851 auto opt = get_option_no_throw(option_name);
6852 if(opt ==
nullptr) {
6860 auto opt = get_option_no_throw(option_name);
6861 if(opt ==
nullptr) {
6868 const Option *
operator[](
const std::string &option_name)
const {
return get_option(option_name); }
6895 std::string
get_footer()
const {
return (footer_callback_) ? footer_callback_() +
'\n' + footer_ : footer_; }
6969 const std::vector<std::string> &
get_aliases()
const {
return aliases_; }
6980 return std::string(
"[Option Group: ") + get_group() +
"]";
6982 if(aliases_.empty() || !with_aliases) {
6985 std::string dispname = name_;
6986 for(
const auto &lalias : aliases_) {
6987 dispname.push_back(
',');
6988 dispname.push_back(
' ');
6989 dispname.append(lalias);
6996 std::string local_name = name_;
6997 if(ignore_underscore_) {
6998 local_name = detail::remove_underscore(name_);
6999 name_to_check = detail::remove_underscore(name_to_check);
7002 local_name = detail::to_lower(name_);
7003 name_to_check = detail::to_lower(name_to_check);
7006 if(local_name == name_to_check) {
7009 for(
auto les : aliases_) {
7010 if(ignore_underscore_) {
7011 les = detail::remove_underscore(les);
7014 les = detail::to_lower(les);
7016 if(les == name_to_check) {
7025 std::vector<std::string> groups;
7027 for(
const Option_p &opt : options_) {
7029 if(std::find(groups.begin(), groups.end(), opt->
get_group()) == groups.end()) {
7038 const std::vector<Option *> &
parse_order()
const {
return parse_order_; }
7041 std::vector<std::string>
remaining(
bool recurse =
false)
const {
7042 std::vector<std::string> miss_list;
7043 for(
const std::pair<detail::Classifier, std::string> &miss : missing_) {
7044 miss_list.push_back(std::get<1>(miss));
7048 if(!allow_extras_) {
7049 for(
const auto &sub : subcommands_) {
7050 if(sub->name_.empty() && !sub->missing_.empty()) {
7051 for(
const std::pair<detail::Classifier, std::string> &miss : sub->missing_) {
7052 miss_list.push_back(std::get<1>(miss));
7059 for(
const App *sub : parsed_subcommands_) {
7060 std::vector<std::string> output = sub->remaining(recurse);
7061 std::copy(std::begin(output), std::end(output), std::back_inserter(miss_list));
7069 std::vector<std::string> miss_list = remaining(recurse);
7070 std::reverse(std::begin(miss_list), std::end(miss_list));
7076 auto remaining_options =
static_cast<std::size_t
>(std::count_if(
7077 std::begin(missing_), std::end(missing_), [](
const std::pair<detail::Classifier, std::string> &val) {
7078 return val.first != detail::Classifier::POSITIONAL_MARK;
7082 for(
const App_p &sub : subcommands_) {
7083 remaining_options += sub->remaining_size(recurse);
7086 return remaining_options;
7098 auto pcount = std::count_if(std::begin(options_), std::end(options_), [](
const Option_p &opt) {
7099 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional();
7102 auto pcount_req = std::count_if(std::begin(options_), std::end(options_), [](
const Option_p &opt) {
7103 return opt->get_items_expected_max() >= detail::expected_max_vector_size && !opt->nonpositional() &&
7104 opt->get_required();
7106 if(pcount - pcount_req > 1) {
7111 std::size_t nameless_subs{0};
7112 for(
const App_p &app : subcommands_) {
7114 if(app->get_name().empty())
7118 if(require_option_min_ > 0) {
7119 if(require_option_max_ > 0) {
7120 if(require_option_max_ < require_option_min_) {
7121 throw(
InvalidError(
"Required min options greater than required max options",
7122 ExitCodes::InvalidError));
7125 if(require_option_min_ > (options_.size() + nameless_subs)) {
7126 throw(
InvalidError(
"Required min options greater than number of available options",
7127 ExitCodes::InvalidError));
7136 if(default_startup == startup_mode::enabled) {
7138 }
else if(default_startup == startup_mode::disabled) {
7141 for(
const App_p &app : subcommands_) {
7142 if(app->has_automatic_name_) {
7145 if(app->name_.empty()) {
7146 app->fallthrough_ =
false;
7147 app->prefix_command_ =
false;
7150 app->parent_ =
this;
7156 void run_callback(
bool final_mode =
false,
bool suppress_final_callback =
false) {
7159 if(!final_mode && parse_complete_callback_) {
7160 parse_complete_callback_();
7163 for(
App *subc : get_subcommands()) {
7164 subc->run_callback(
true, suppress_final_callback);
7167 for(
auto &subc : subcommands_) {
7168 if(subc->name_.empty() && subc->count_all() > 0) {
7169 subc->run_callback(
true, suppress_final_callback);
7174 if(final_callback_ && (parsed_ > 0) && (!suppress_final_callback)) {
7175 if(!name_.empty() || count_all() > 0 || parent_ ==
nullptr) {
7184 if(require_subcommand_max_ != 0 && parsed_subcommands_.size() >= require_subcommand_max_) {
7185 return parent_ !=
nullptr && parent_->_valid_subcommand(current, ignore_used);
7187 auto com = _find_subcommand(current,
true, ignore_used);
7188 if(com !=
nullptr) {
7192 return parent_ !=
nullptr && parent_->_valid_subcommand(current, ignore_used);
7197 std::string dummy1, dummy2;
7200 return detail::Classifier::POSITIONAL_MARK;
7201 if(_valid_subcommand(current, ignore_used_subcommands))
7202 return detail::Classifier::SUBCOMMAND;
7203 if(detail::split_long(current, dummy1, dummy2))
7204 return detail::Classifier::LONG;
7205 if(detail::split_short(current, dummy1, dummy2)) {
7206 if(dummy1[0] >=
'0' && dummy1[0] <=
'9') {
7207 if(get_option_no_throw(std::string{
'-', dummy1[0]}) ==
nullptr) {
7208 return detail::Classifier::NONE;
7211 return detail::Classifier::SHORT;
7213 if((allow_windows_style_options_) && (detail::split_windows_style(current, dummy1, dummy2)))
7214 return detail::Classifier::WINDOWS_STYLE;
7215 if((current ==
"++") && !name_.empty() && parent_ !=
nullptr)
7216 return detail::Classifier::SUBCOMMAND_TERMINATOR;
7217 return detail::Classifier::NONE;
7224 if(config_ptr_ !=
nullptr) {
7225 bool config_required = config_ptr_->get_required();
7226 auto file_given = config_ptr_->count() > 0;
7227 auto config_files = config_ptr_->as<std::vector<std::string>>();
7228 if(config_files.empty() || config_files.front().empty()) {
7229 if(config_required) {
7230 throw FileError::Missing(
"no specified config file");
7234 for(
auto rit = config_files.rbegin(); rit != config_files.rend(); ++rit) {
7235 const auto &config_file = *rit;
7236 auto path_result = detail::check_path(config_file.c_str());
7237 if(path_result == detail::path_type::file) {
7239 std::vector<ConfigItem> values = config_formatter_->from_file(config_file);
7240 _parse_config(values);
7242 config_ptr_->add_result(config_file);
7245 if(config_required || file_given)
7248 }
else if(config_required || file_given) {
7249 throw FileError::Missing(config_file);
7257 for(
const Option_p &opt : options_) {
7259 char *buffer =
nullptr;
7260 std::string ename_string;
7265 if(_dupenv_s(&buffer, &sz, opt->
envname_.c_str()) == 0 && buffer !=
nullptr) {
7266 ename_string = std::string(buffer);
7271 buffer = std::getenv(opt->
envname_.c_str());
7272 if(buffer !=
nullptr)
7273 ename_string = std::string(buffer);
7276 if(!ename_string.empty()) {
7282 for(
App_p &sub : subcommands_) {
7283 if(sub->get_name().empty() || !sub->parse_complete_callback_)
7284 sub->_process_env();
7291 for(
App_p &sub : subcommands_) {
7293 if(sub->get_name().empty() && sub->parse_complete_callback_) {
7294 if(sub->count_all() > 0) {
7295 sub->_process_callbacks();
7296 sub->run_callback();
7301 for(
const Option_p &opt : options_) {
7306 for(
App_p &sub : subcommands_) {
7307 if(!sub->parse_complete_callback_) {
7308 sub->_process_callbacks();
7317 const Option *help_ptr = get_help_ptr();
7318 const Option *help_all_ptr = get_help_all_ptr();
7320 if(help_ptr !=
nullptr && help_ptr->
count() > 0)
7321 trigger_help =
true;
7322 if(help_all_ptr !=
nullptr && help_all_ptr->
count() > 0)
7323 trigger_all_help =
true;
7326 if(!parsed_subcommands_.empty()) {
7327 for(
const App *sub : parsed_subcommands_)
7328 sub->_process_help_flags(trigger_help, trigger_all_help);
7331 }
else if(trigger_all_help) {
7333 }
else if(trigger_help) {
7341 bool excluded{
false};
7342 std::string excluder;
7343 for(
auto &opt : exclude_options_) {
7344 if(opt->
count() > 0) {
7349 for(
auto &subc : exclude_subcommands_) {
7350 if(subc->count_all() > 0) {
7352 excluder = subc->get_display_name();
7356 if(count_all() > 0) {
7364 bool missing_needed{
false};
7365 std::string missing_need;
7366 for(
auto &opt : need_options_) {
7367 if(opt->
count() == 0) {
7368 missing_needed =
true;
7372 for(
auto &subc : need_subcommands_) {
7373 if(subc->count_all() == 0) {
7374 missing_needed =
true;
7375 missing_need = subc->get_display_name();
7378 if(missing_needed) {
7379 if(count_all() > 0) {
7386 std::size_t used_options = 0;
7387 for(
const Option_p &opt : options_) {
7389 if(opt->
count() != 0) {
7398 if(opt->
count() > 0 && opt_req->count() == 0)
7402 if(opt->
count() > 0 && opt_ex->count() != 0)
7406 if(require_subcommand_min_ > 0) {
7407 auto selected_subcommands = get_subcommands();
7408 if(require_subcommand_min_ > selected_subcommands.size())
7409 throw RequiredError::Subcommand(require_subcommand_min_);
7416 for(
App_p &sub : subcommands_) {
7419 if(sub->name_.empty() && sub->count_all() > 0) {
7424 if(require_option_min_ > used_options || (require_option_max_ > 0 && require_option_max_ < used_options)) {
7425 auto option_list = detail::join(options_, [
this](
const Option_p &ptr) {
7426 if(ptr.get() == help_ptr_ || ptr.get() == help_all_ptr_) {
7427 return std::string{};
7429 return ptr->get_name(
false,
true);
7432 auto subc_list = get_subcommands([](
App *app) {
return ((app->
get_name().empty()) && (!app->
disabled_)); });
7433 if(!subc_list.empty()) {
7434 option_list +=
"," + detail::join(subc_list, [](
const App *app) {
return app->
get_display_name(); });
7436 throw RequiredError::Option(require_option_min_, require_option_max_, used_options, option_list);
7440 for(
App_p &sub : subcommands_) {
7443 if(sub->name_.empty() && sub->required_ ==
false) {
7444 if(sub->count_all() == 0) {
7445 if(require_option_min_ > 0 && require_option_min_ <= used_options) {
7450 if(require_option_max_ > 0 && used_options >= require_option_min_) {
7457 if(sub->count() > 0 || sub->name_.empty()) {
7458 sub->_process_requirements();
7461 if(sub->required_ && sub->count_all() == 0) {
7470 bool caught_error{
false};
7474 _process_config_file();
7479 caught_error =
true;
7483 _process_callbacks();
7484 _process_help_flags();
7490 _process_requirements();
7495 if(!(allow_extras_ || prefix_command_)) {
7496 std::size_t num_left_over = remaining_size();
7497 if(num_left_over > 0) {
7502 for(
App_p &sub : subcommands_) {
7503 if(sub->count() > 0)
7504 sub->_process_extras();
7511 if(!(allow_extras_ || prefix_command_)) {
7512 std::size_t num_left_over = remaining_size();
7513 if(num_left_over > 0) {
7514 args = remaining(
false);
7519 for(
App_p &sub : subcommands_) {
7520 if(sub->count() > 0)
7521 sub->_process_extras(args);
7528 for(
App_p &sub : subcommands_) {
7529 if(sub->get_name().empty())
7530 sub->increment_parsed();
7534 void _parse(std::vector<std::string> &args) {
7536 _trigger_pre_parse(args.size());
7537 bool positional_only =
false;
7539 while(!args.empty()) {
7540 if(!_parse_single(args, positional_only)) {
7545 if(parent_ ==
nullptr) {
7549 _process_extras(args);
7552 args = remaining_for_passthrough(
false);
7553 }
else if(parse_complete_callback_) {
7555 _process_callbacks();
7556 _process_help_flags();
7557 _process_requirements();
7558 run_callback(
false,
true);
7563 void _parse(std::vector<std::string> &&args) {
7567 _trigger_pre_parse(args.size());
7568 bool positional_only =
false;
7570 while(!args.empty()) {
7571 _parse_single(args, positional_only);
7581 auto values = config_formatter_->from_config(input);
7582 _parse_config(values);
7584 _trigger_pre_parse(values.size());
7597 if(!_parse_single_config(item) && allow_config_extras_ == config_extras_mode::error)
7598 throw ConfigError::Extras(item.fullname());
7604 if(level < item.
parents.size()) {
7606 auto subcom = get_subcommand(item.
parents.at(level));
7607 auto result = subcom->_parse_single_config(item, level + 1);
7615 if(item.
name ==
"++") {
7618 _trigger_pre_parse(2);
7619 if(parent_ !=
nullptr) {
7620 parent_->parsed_subcommands_.push_back(
this);
7626 if(item.
name ==
"--") {
7628 _process_callbacks();
7629 _process_requirements();
7634 Option *op = get_option_no_throw(
"--" + item.
name);
7636 if(item.
name.size() == 1) {
7637 op = get_option_no_throw(
"-" + item.
name);
7641 op = get_option_no_throw(item.
name);
7645 if(get_allow_config_extras() == config_extras_mode::capture)
7647 missing_.emplace_back(detail::Classifier::NONE, item.
fullname());
7652 if(get_allow_config_extras() == config_extras_mode::ignore_all) {
7655 throw ConfigError::NotConfigurable(item.
fullname());
7661 auto res = config_formatter_->to_flag(item);
7679 detail::Classifier classifier = positional_only ? detail::Classifier::NONE : _recognize(args.back());
7680 switch(classifier) {
7681 case detail::Classifier::POSITIONAL_MARK:
7683 positional_only =
true;
7684 if((!_has_remaining_positionals()) && (parent_ !=
nullptr)) {
7687 _move_to_missing(classifier,
"--");
7690 case detail::Classifier::SUBCOMMAND_TERMINATOR:
7695 case detail::Classifier::SUBCOMMAND:
7696 retval = _parse_subcommand(args);
7698 case detail::Classifier::LONG:
7699 case detail::Classifier::SHORT:
7700 case detail::Classifier::WINDOWS_STYLE:
7702 _parse_arg(args, classifier);
7704 case detail::Classifier::NONE:
7706 retval = _parse_positional(args,
false);
7707 if(retval && positionals_at_end_) {
7708 positional_only =
true;
7713 throw HorribleError(
"unrecognized classifier (you should not see this!)");
7721 std::size_t retval = 0;
7722 for(
const Option_p &opt : options_) {
7735 for(
const Option_p &opt : options_) {
7749 const std::string &positional = args.back();
7751 if(positionals_at_end_) {
7753 auto arg_rem = args.size();
7754 auto remreq = _count_remaining_positionals(
true);
7755 if(arg_rem <= remreq) {
7756 for(
const Option_p &opt : options_) {
7759 if(validate_positionals_) {
7760 std::string pos = positional;
7761 pos = opt->_validate(pos, 0);
7767 parse_order_.push_back(opt.get());
7775 for(
const Option_p &opt : options_) {
7779 if(validate_positionals_) {
7780 std::string pos = positional;
7781 pos = opt->_validate(pos, 0);
7787 parse_order_.push_back(opt.get());
7793 for(
auto &subc : subcommands_) {
7794 if((subc->name_.empty()) && (!subc->disabled_)) {
7795 if(subc->_parse_positional(args,
false)) {
7796 if(!subc->pre_parse_called_) {
7797 subc->_trigger_pre_parse(args.size());
7804 if(parent_ !=
nullptr && fallthrough_)
7805 return _get_fallthrough_parent()->_parse_positional(args,
static_cast<bool>(parse_complete_callback_));
7808 auto com = _find_subcommand(args.back(),
true,
false);
7809 if(com !=
nullptr && (require_subcommand_max_ == 0 || require_subcommand_max_ > parsed_subcommands_.size())) {
7810 if(haltOnSubcommand) {
7819 auto parent_app = (parent_ !=
nullptr) ? _get_fallthrough_parent() :
this;
7820 com = parent_app->_find_subcommand(args.back(),
true,
false);
7821 if(com !=
nullptr && (com->parent_->require_subcommand_max_ == 0 ||
7822 com->parent_->require_subcommand_max_ > com->parent_->parsed_subcommands_.size())) {
7826 if(positionals_at_end_) {
7830 if(parent_ !=
nullptr && name_.empty()) {
7834 _move_to_missing(detail::Classifier::NONE, positional);
7836 if(prefix_command_) {
7837 while(!args.empty()) {
7838 _move_to_missing(detail::Classifier::NONE, args.back());
7849 for(
const App_p &com : subcommands_) {
7850 if(com->disabled_ && ignore_disabled)
7852 if(com->get_name().empty()) {
7853 auto subc = com->
_find_subcommand(subc_name, ignore_disabled, ignore_used);
7854 if(subc !=
nullptr) {
7858 if(com->check_name(subc_name)) {
7859 if((!*com) || !ignore_used)
7871 if(_count_remaining_positionals(
true) > 0) {
7872 _parse_positional(args,
false);
7875 auto com = _find_subcommand(args.back(),
true,
true);
7876 if(com !=
nullptr) {
7879 parsed_subcommands_.push_back(com);
7882 auto parent_app = com->parent_;
7883 while(parent_app !=
this) {
7884 parent_app->_trigger_pre_parse(args.size());
7886 parent_app->parsed_subcommands_.push_back(com);
7888 parent_app = parent_app->parent_;
7893 if(parent_ ==
nullptr)
7894 throw HorribleError(
"Subcommand " + args.back() +
" missing");
7902 std::string current = args.back();
7904 std::string arg_name;
7908 switch(current_type) {
7909 case detail::Classifier::LONG:
7910 if(!detail::split_long(current, arg_name, value))
7911 throw HorribleError(
"Long parsed but missing (you should not see this):" + args.back());
7913 case detail::Classifier::SHORT:
7914 if(!detail::split_short(current, arg_name, rest))
7915 throw HorribleError(
"Short parsed but missing! You should not see this");
7917 case detail::Classifier::WINDOWS_STYLE:
7918 if(!detail::split_windows_style(current, arg_name, value))
7919 throw HorribleError(
"windows option parsed but missing! You should not see this");
7921 case detail::Classifier::SUBCOMMAND:
7922 case detail::Classifier::SUBCOMMAND_TERMINATOR:
7923 case detail::Classifier::POSITIONAL_MARK:
7924 case detail::Classifier::NONE:
7926 throw HorribleError(
"parsing got called with invalid option! You should not see this");
7930 std::find_if(std::begin(options_), std::end(options_), [arg_name, current_type](
const Option_p &opt) {
7931 if(current_type == detail::Classifier::LONG)
7932 return opt->check_lname(arg_name);
7933 if(current_type == detail::Classifier::SHORT)
7934 return opt->check_sname(arg_name);
7936 return opt->check_lname(arg_name) || opt->check_sname(arg_name);
7940 if(op_ptr == std::end(options_)) {
7941 for(
auto &subc : subcommands_) {
7942 if(subc->name_.empty() && !subc->disabled_) {
7943 if(subc->_parse_arg(args, current_type)) {
7944 if(!subc->pre_parse_called_) {
7945 subc->_trigger_pre_parse(args.size());
7952 if(parent_ !=
nullptr && fallthrough_)
7953 return _get_fallthrough_parent()->_parse_arg(args, current_type);
7955 if(parent_ !=
nullptr && name_.empty()) {
7960 _move_to_missing(current_type, current);
7969 if(op->get_inject_separator()) {
7970 if(!op->results().empty() && !op->results().back().empty()) {
7971 op->add_result(std::string{});
7974 if(op->get_trigger_on_parse() && op->current_option_state_ == Option::option_state::callback_run) {
7977 int min_num = (std::min)(op->get_type_size_min(), op->get_items_expected_min());
7978 int max_num = op->get_items_expected_max();
7981 if(max_num >= detail::expected_max_vector_size / 16 && !op->get_allow_extra_args()) {
7982 auto tmax = op->get_type_size_max();
7983 max_num = detail::checked_multiply(tmax, op->get_expected_min()) ? tmax : detail::expected_max_vector_size;
7987 int result_count = 0;
7990 auto res = op->get_flag_value(arg_name, value);
7991 op->add_result(res);
7992 parse_order_.push_back(op.get());
7993 }
else if(!value.empty()) {
7994 op->add_result(value, result_count);
7995 parse_order_.push_back(op.get());
7996 collected += result_count;
7998 }
else if(!rest.empty()) {
7999 op->add_result(rest, result_count);
8000 parse_order_.push_back(op.get());
8002 collected += result_count;
8006 while(min_num > collected && !args.empty()) {
8007 std::string current_ = args.back();
8009 op->add_result(current_, result_count);
8010 parse_order_.push_back(op.get());
8011 collected += result_count;
8014 if(min_num > collected) {
8015 throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
8018 if(max_num > collected || op->get_allow_extra_args()) {
8019 auto remreqpos = _count_remaining_positionals(
true);
8021 while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
8022 _recognize(args.back(),
false) == detail::Classifier::NONE) {
8024 if(remreqpos >= args.size()) {
8028 op->add_result(args.back(), result_count);
8029 parse_order_.push_back(op.get());
8031 collected += result_count;
8035 if(!args.empty() && _recognize(args.back()) == detail::Classifier::POSITIONAL_MARK)
8038 if(min_num == 0 && max_num > 0 && collected == 0) {
8039 auto res = op->get_flag_value(arg_name, std::string{});
8040 op->add_result(res);
8041 parse_order_.push_back(op.get());
8046 if(min_num > 0 && op->get_type_size_max() != min_num && (collected % op->get_type_size_max()) != 0) {
8047 op->add_result(std::string{});
8049 if(op->get_trigger_on_parse()) {
8054 args.push_back(rest);
8061 if(!pre_parse_called_) {
8062 pre_parse_called_ =
true;
8063 if(pre_parse_callback_) {
8064 pre_parse_callback_(remaining_args);
8066 }
else if(immediate_callback_) {
8067 if(!name_.empty()) {
8068 auto pcnt = parsed_;
8069 auto extras = std::move(missing_);
8072 pre_parse_called_ =
true;
8073 missing_ = std::move(extras);
8080 if(parent_ ==
nullptr) {
8083 auto fallthrough_parent = parent_;
8084 while((fallthrough_parent->parent_ !=
nullptr) && (fallthrough_parent->get_name().empty())) {
8085 fallthrough_parent = fallthrough_parent->
parent_;
8087 return fallthrough_parent;
8092 static const std::string estring;
8097 if(subc.get() != &subcom) {
8098 if(subc->disabled_) {
8102 if(subc->check_name(subcom.
get_name())) {
8106 if(!subc->get_name().empty()) {
8108 return subc->get_name();
8111 for(
const auto &les : subcom.
aliases_) {
8112 if(subc->check_name(les)) {
8117 for(
const auto &les : subc->aliases_) {
8123 if(subc->get_name().empty()) {
8124 auto &cmpres = _compare_subcommand_names(subcom, *subc);
8125 if(!cmpres.empty()) {
8131 auto &cmpres = _compare_subcommand_names(*subc, subcom);
8132 if(!cmpres.empty()) {
8142 if(allow_extras_ || subcommands_.empty()) {
8143 missing_.emplace_back(val_type, val);
8147 for(
auto &subc : subcommands_) {
8148 if(subc->name_.empty() && subc->allow_extras_) {
8149 subc->missing_.emplace_back(val_type, val);
8154 missing_.emplace_back(val_type, val);
8160 if(opt ==
nullptr) {
8165 for(
auto &subc : subcommands_) {
8166 if(app == subc.get()) {
8174 if((help_ptr_ == opt) || (help_all_ptr_ == opt))
8177 if(config_ptr_ == opt)
8181 std::find_if(std::begin(options_), std::end(options_), [opt](
const Option_p &v) {
return v.get() == opt; });
8182 if(iterator != std::end(options_)) {
8183 const auto &opt_p = *iterator;
8185 return (*v == *opt_p);
8188 app->
options_.push_back(std::move(*iterator));
8189 options_.erase(iterator);
8203 :
App(std::move(group_description),
"", parent) {
8207 using App::add_option;
8210 if(get_parent() ==
nullptr) {
8213 get_parent()->_move_option(opt,
this);
8221 add_options(args...);
8223 using App::add_subcommand;
8227 subc->get_parent()->remove_subcommand(subcom);
8228 add_subcommand(std::move(subc));
8240inline void TriggerOn(
App *trigger_app, std::vector<App *> apps_to_enable) {
8241 for(
auto &app : apps_to_enable) {
8242 app->enabled_by_default(
false);
8243 app->disabled_by_default();
8247 for(
auto &app : apps_to_enable) {
8248 app->disabled(
false);
8262 for(
auto &app : apps_to_enable) {
8263 app->disabled_by_default(
false);
8264 app->enabled_by_default();
8268 for(
auto &app : apps_to_enable) {
8276 Validator deprecate_warning{[opt, replacement](std::string &) {
8277 std::cout << opt->
get_name() <<
" is deprecated please use '" << replacement
8279 return std::string();
8282 deprecate_warning.application_index(0);
8283 opt->
check(deprecate_warning);
8284 if(!replacement.empty()) {
8310 auto opt2 = app->
add_option(option_copy->get_name(
false,
true),
"option has been retired and has no effect")
8313 ->
type_size(option_copy->get_type_size_min(), option_copy->get_type_size_max())
8314 ->
expected(option_copy->get_expected_min(), option_copy->get_expected_max())
8317 Validator retired_warning{[opt2](std::string &) {
8318 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
8319 return std::string();
8322 retired_warning.application_index(0);
8323 opt2->check(retired_warning);
8333 if(opt !=
nullptr) {
8337 auto opt2 = app->
add_option(option_name,
"option has been retired and has no effect")
8341 Validator retired_warning{[opt2](std::string &) {
8342 std::cout <<
"WARNING " << opt2->
get_name() <<
" is retired and has no effect\n";
8343 return std::string();
8346 retired_warning.application_index(0);
8347 opt2->check(retired_warning);
8353namespace FailureMessage {
8357 std::string header = std::string(e.what()) +
"\n";
8358 std::vector<std::string> names;
8369 header +=
"Run with " + detail::join(names,
" or ") +
" for more information.\n";
8376 std::string header = std::string(
"ERROR: ") + e.
get_name() +
": " + e.what() +
"\n";
8377 header += app->
help();
8389 template <
typename... Args>
static decltype(
auto) parse_arg(
App *app, Args &&...args) {
8390 return app->
_parse_arg(std::forward<Args>(args)...);
8394 template <
typename... Args>
static decltype(
auto) parse_subcommand(
App *app, Args &&...args) {
8399 template <
typename... Args>
8401 typename std::result_of<
decltype (&App::_parse_arg)(
App, Args...)>::type {
8402 return app->
_parse_arg(std::forward<Args>(args)...);
8406 template <
typename... Args>
8408 typename std::result_of<
decltype (&App::_parse_subcommand)(
App, Args...)>::type {
8422inline std::string
convert_arg_for_ini(
const std::string &arg,
char stringQuote =
'"',
char characterQuote =
'\'') {
8424 return std::string(2, stringQuote);
8427 if(arg ==
"true" || arg ==
"false" || arg ==
"nan" || arg ==
"inf") {
8431 if(arg.compare(0, 2,
"0x") != 0 && arg.compare(0, 2,
"0X") != 0) {
8433 if(detail::lexical_cast(arg, val)) {
8438 if(arg.size() == 1) {
8439 return std::string(1, characterQuote) + arg + characterQuote;
8442 if(arg.front() ==
'0') {
8444 if(std::all_of(arg.begin() + 2, arg.end(), [](
char x) {
8445 return (x >=
'0' && x <=
'9') || (x >=
'A' && x <=
'F') || (x >=
'a' && x <=
'f');
8449 }
else if(arg[1] ==
'o') {
8450 if(std::all_of(arg.begin() + 2, arg.end(), [](
char x) { return (x >=
'0' && x <=
'7'); })) {
8453 }
else if(arg[1] ==
'b') {
8454 if(std::all_of(arg.begin() + 2, arg.end(), [](
char x) { return (x ==
'0' || x ==
'1'); })) {
8459 if(arg.find_first_of(stringQuote) == std::string::npos) {
8460 return std::string(1, stringQuote) + arg + stringQuote;
8462 return characterQuote + arg + characterQuote;
8467inline std::string
ini_join(
const std::vector<std::string> &args,
8469 char arrayStart =
'[',
8470 char arrayEnd =
']',
8471 char stringQuote =
'"',
8472 char characterQuote =
'\'') {
8474 if(args.size() > 1 && arrayStart !=
'\0') {
8475 joined.push_back(arrayStart);
8477 std::size_t start = 0;
8478 for(
const auto &arg : args) {
8480 joined.push_back(sepChar);
8481 if(isspace(sepChar) == 0) {
8482 joined.push_back(
' ');
8487 if(args.size() > 1 && arrayEnd !=
'\0') {
8488 joined.push_back(arrayEnd);
8493inline std::vector<std::string>
generate_parents(
const std::string §ion, std::string &name,
char parentSeparator) {
8494 std::vector<std::string> parents;
8495 if(detail::to_lower(section) !=
"default") {
8496 if(section.find(parentSeparator) != std::string::npos) {
8497 parents = detail::split(section, parentSeparator);
8499 parents = {section};
8502 if(name.find(parentSeparator) != std::string::npos) {
8503 std::vector<std::string> plist = detail::split(name, parentSeparator);
8504 name = plist.back();
8505 detail::remove_quotes(name);
8507 parents.insert(parents.end(), plist.begin(), plist.end());
8511 for(
auto &parent : parents) {
8512 detail::remove_quotes(parent);
8519checkParentSegments(std::vector<ConfigItem> &output,
const std::string ¤tSection,
char parentSeparator) {
8521 std::string estring;
8522 auto parents = detail::generate_parents(currentSection, estring, parentSeparator);
8523 if(!output.empty() && output.back().name ==
"--") {
8524 std::size_t msize = (parents.size() > 1U) ? parents.size() : 2;
8525 while(output.back().parents.size() >= msize) {
8526 output.push_back(output.back());
8527 output.back().parents.pop_back();
8530 if(parents.size() > 1) {
8531 std::size_t common = 0;
8532 std::size_t mpair = (std::min)(output.back().parents.size(), parents.size() - 1);
8533 for(std::size_t ii = 0; ii < mpair; ++ii) {
8534 if(output.back().parents[ii] != parents[ii]) {
8539 if(common == mpair) {
8542 while(output.back().parents.size() > common + 1) {
8543 output.push_back(output.back());
8544 output.back().parents.pop_back();
8547 for(std::size_t ii = common; ii < parents.size() - 1; ++ii) {
8548 output.emplace_back();
8549 output.back().parents.assign(parents.begin(), parents.begin() +
static_cast<std::ptrdiff_t
>(ii) + 1);
8550 output.back().name =
"++";
8553 }
else if(parents.size() > 1) {
8554 for(std::size_t ii = 0; ii < parents.size() - 1; ++ii) {
8555 output.emplace_back();
8556 output.back().parents.assign(parents.begin(), parents.begin() +
static_cast<std::ptrdiff_t
>(ii) + 1);
8557 output.back().name =
"++";
8562 output.emplace_back();
8563 output.back().parents = std::move(parents);
8564 output.back().name =
"++";
8570 std::string currentSection =
"default";
8571 std::string previousSection =
"default";
8572 std::vector<ConfigItem> output;
8573 bool isDefaultArray = (arrayStart ==
'[' && arrayEnd ==
']' && arraySeparator ==
',');
8574 bool isINIArray = (arrayStart ==
'\0' || arrayStart ==
' ') && arrayStart == arrayEnd;
8575 bool inSection{
false};
8576 char aStart = (isINIArray) ?
'[' : arrayStart;
8577 char aEnd = (isINIArray) ?
']' : arrayEnd;
8578 char aSep = (isINIArray && arraySeparator ==
' ') ?
',' : arraySeparator;
8579 int currentSectionIndex{0};
8580 while(getline(input, line)) {
8581 std::vector<std::string> items_buffer;
8585 std::size_t len = line.length();
8590 if(line.front() ==
'[' && line.back() ==
']') {
8591 if(currentSection !=
"default") {
8593 output.emplace_back();
8595 output.back().name =
"--";
8597 currentSection = line.substr(1, len - 2);
8599 if(currentSection.size() > 1 && currentSection.front() ==
'[' && currentSection.back() ==
']') {
8600 currentSection = currentSection.substr(1, currentSection.size() - 2);
8603 currentSection =
"default";
8608 if(currentSection == previousSection) {
8609 ++currentSectionIndex;
8611 currentSectionIndex = 0;
8612 previousSection = currentSection;
8618 if(line.front() ==
';' || line.front() ==
'#' || line.front() == commentChar) {
8623 auto pos = line.find(valueDelimiter);
8624 if(pos != std::string::npos) {
8627 auto cloc = item.find(commentChar);
8628 if(cloc != std::string::npos) {
8629 item.erase(cloc, std::string::npos);
8632 if(item.size() > 1 && item.front() == aStart) {
8633 for(std::string multiline; item.back() != aEnd && std::getline(input, multiline);) {
8638 }
else if((isDefaultArray || isINIArray) && item.find_first_of(aSep) != std::string::npos) {
8640 }
else if((isDefaultArray || isINIArray) && item.find_first_of(
' ') != std::string::npos) {
8643 items_buffer = {item};
8647 auto cloc = name.find(commentChar);
8648 if(cloc != std::string::npos) {
8649 name.erase(cloc, std::string::npos);
8653 items_buffer = {
"true"};
8655 if(name.find(parentSeparatorChar) == std::string::npos) {
8659 for(
auto &it : items_buffer) {
8664 if(parents.size() > maximumLayers) {
8667 if(!configSection.empty() && !inSection) {
8668 if(parents.empty() || parents.front() != configSection) {
8671 if(configIndex >= 0 && currentSectionIndex != configIndex) {
8674 parents.erase(parents.begin());
8677 if(!output.empty() && name == output.back().name && parents == output.back().parents) {
8678 output.back().inputs.insert(output.back().inputs.end(), items_buffer.begin(), items_buffer.end());
8680 output.emplace_back();
8681 output.back().parents = std::move(parents);
8682 output.back().name = std::move(name);
8683 output.back().inputs = std::move(items_buffer);
8686 if(currentSection !=
"default") {
8689 output.emplace_back();
8691 output.back().name =
"--";
8692 while(output.back().parents.size() > 1) {
8693 output.push_back(output.back());
8694 output.back().parents.pop_back();
8702 std::stringstream out;
8703 std::string commentLead;
8704 commentLead.push_back(commentChar);
8705 commentLead.push_back(
' ');
8707 std::vector<std::string> groups = app->
get_groups();
8708 bool defaultUsed =
false;
8709 groups.insert(groups.begin(), std::string(
"Options"));
8713 for(
auto &group : groups) {
8714 if(group ==
"Options" || group.empty()) {
8720 if(write_description && group !=
"Options" && !group.empty()) {
8721 out <<
'\n' << commentLead << group <<
" Options\n";
8728 if(!(group ==
"Options" && opt->
get_group().empty())) {
8734 opt->
reduced_results(), arraySeparator, arrayStart, arrayEnd, stringQuote, characterQuote);
8736 if(value.empty() && default_also) {
8746 if(!value.empty()) {
8751 out << name << valueDelimiter << value <<
'\n';
8757 for(
const App *subcom : subcommands) {
8758 if(subcom->get_name().empty()) {
8759 if(write_description && !subcom->get_group().empty()) {
8760 out <<
'\n' << commentLead << subcom->get_group() <<
" Options\n";
8762 out << to_config(subcom, default_also, write_description, prefix);
8766 for(
const App *subcom : subcommands) {
8767 if(!subcom->get_name().empty()) {
8769 if(!prefix.empty() || app->
get_parent() ==
nullptr) {
8770 out <<
'[' << prefix << subcom->get_name() <<
"]\n";
8772 std::string subname = app->
get_name() + parentSeparatorChar + subcom->get_name();
8774 while(p->get_parent() !=
nullptr) {
8775 subname = p->
get_name() + parentSeparatorChar + subname;
8776 p = p->get_parent();
8778 out <<
'[' << subname <<
"]\n";
8780 out << to_config(subcom, default_also, write_description,
"");
8783 subcom, default_also, write_description, prefix + subcom->get_name() + parentSeparatorChar);
8796 std::stringstream out;
8798 out <<
"\n" << group <<
":\n";
8799 for(
const Option *opt : opts) {
8800 out << make_option(opt, is_positional);
8807 std::vector<const Option *> opts =
8811 return std::string();
8813 return make_group(get_label(
"Positionals"),
true, opts);
8817 std::stringstream out;
8818 std::vector<std::string> groups = app->
get_groups();
8821 for(
const std::string &group : groups) {
8822 std::vector<const Option *> opts = app->
get_options([app, mode, &group](
const Option *opt) {
8829 if(!group.empty() && !opts.empty()) {
8830 out << make_group(group,
false, opts);
8832 if(group != groups.back())
8845 desc +=
" REQUIRED ";
8847 if((max_options == min_options) && (min_options > 0)) {
8848 if(min_options == 1) {
8849 desc +=
" \n[Exactly 1 of the following options is required]";
8851 desc +=
" \n[Exactly " + std::to_string(min_options) +
"options from the following list are required]";
8853 }
else if(max_options > 0) {
8854 if(min_options > 0) {
8855 desc +=
" \n[Between " + std::to_string(min_options) +
" and " + std::to_string(max_options) +
8856 " of the follow options are required]";
8858 desc +=
" \n[At most " + std::to_string(max_options) +
" of the following options are allowed]";
8860 }
else if(min_options > 0) {
8861 desc +=
" \n[At least " + std::to_string(min_options) +
" of the following options are required]";
8863 return (!desc.empty()) ? desc +
"\n" : std::string{};
8867 std::stringstream out;
8869 out << get_label(
"Usage") <<
":" << (name.empty() ?
"" :
" ") << name;
8871 std::vector<std::string> groups = app->
get_groups();
8874 std::vector<const Option *> non_pos_options =
8876 if(!non_pos_options.empty())
8877 out <<
" [" << get_label(
"OPTIONS") <<
"]";
8883 if(!positionals.empty()) {
8885 std::vector<std::string> positional_names(positionals.size());
8886 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
8887 return make_option_usage(opt);
8895 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
8910 if(footer.empty()) {
8911 return std::string{};
8913 return footer +
"\n";
8921 return make_expanded(app);
8923 std::stringstream out;
8930 out << make_description(app);
8931 out << make_usage(app, name);
8932 out << make_positionals(app);
8933 out << make_groups(app, mode);
8934 out << make_subcommands(app, mode);
8935 out <<
'\n' << make_footer(app);
8941 std::stringstream out;
8946 std::vector<std::string> subcmd_groups_seen;
8947 for(
const App *com : subcommands) {
8948 if(com->get_name().empty()) {
8949 if(!com->get_group().empty()) {
8950 out << make_expanded(com);
8954 std::string group_key = com->get_group();
8955 if(!group_key.empty() &&
8956 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
8957 return detail::to_lower(a) == detail::to_lower(group_key);
8958 }) == subcmd_groups_seen.end())
8959 subcmd_groups_seen.push_back(group_key);
8963 for(
const std::string &group : subcmd_groups_seen) {
8964 out <<
"\n" << group <<
":\n";
8967 for(
const App *new_com : subcommands_group) {
8968 if(new_com->get_name().empty())
8971 out << make_subcommand(new_com);
8983 std::stringstream out;
8989 std::stringstream out;
8992 out << make_description(sub);
8996 out << make_positionals(sub);
9002 tmp = tmp.substr(0, tmp.size() - 1);
9016 std::stringstream out;
9032 out <<
" " << get_label(
"REQUIRED");
9035 out <<
" (" << get_label(
"Env") <<
":" << opt->
get_envname() <<
")";
9037 out <<
" " << get_label(
"Needs") <<
":";
9039 out <<
" " << op->get_name();
9042 out <<
" " << get_label(
"Excludes") <<
":";
9044 out <<
" " << op->get_name();
9054 std::stringstream out;
9055 out << make_option_name(opt,
true);
9061 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
const Regex sep
Definition BasisParser.cxx:13
#define CLI11_ERROR_SIMPLE(name)
Definition CLI11.hpp:562
#define CLI11_ERROR_DEF(parent, name)
Definition CLI11.hpp:551
std::ostream & operator<<(std::ostream &s, const FcidumpReader::FcidumpHeader &h)
Definition FcidumpWriter.cxx:25
int main(int argumentCount, char **arguments)
Definition Sisi4s.cxx:278
Creates a command line program, with very few defaults.
Definition CLI11.hpp:5286
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
Definition CLI11.hpp:7677
bool get_disabled_by_default() const
Get the status of disabled by default.
Definition CLI11.hpp:6928
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition CLI11.hpp:6868
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition CLI11.hpp:5722
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
Definition CLI11.hpp:7256
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 CLI11.hpp:8079
void _process()
Process callbacks and such.
Definition CLI11.hpp:7468
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 CLI11.hpp:5958
void parse(std::string commandline, bool program_name_included=false)
Definition CLI11.hpp:6442
Option * add_option_no_stream(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition CLI11.hpp:5853
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition CLI11.hpp:5892
App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
Definition CLI11.hpp:6288
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition CLI11.hpp:5755
bool remove_excludes(App *app)
Removes a subcommand from the excludes list of this subcommand.
Definition CLI11.hpp:6665
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition CLI11.hpp:5671
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 CLI11.hpp:5630
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
Definition CLI11.hpp:5694
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
Definition CLI11.hpp:7603
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 CLI11.hpp:5939
void _parse(std::vector< std::string > &args)
Internal parse function.
Definition CLI11.hpp:7534
std::size_t get_require_option_min() const
Get the required min option value.
Definition CLI11.hpp:6904
void _parse(std::vector< std::string > &&args)
Internal parse function.
Definition CLI11.hpp:7563
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition CLI11.hpp:5624
bool get_configurable() const
Check the status of the allow windows style options.
Definition CLI11.hpp:6889
App * clear_aliases()
clear all the aliases of the current App
Definition CLI11.hpp:6972
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition CLI11.hpp:5606
App * fallthrough(bool value=true)
Definition CLI11.hpp:6384
Option * get_config_ptr()
Get a pointer to the config option.
Definition CLI11.hpp:6948
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 CLI11.hpp:7182
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition CLI11.hpp:5409
std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Definition CLI11.hpp:6718
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
Definition CLI11.hpp:6143
bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition CLI11.hpp:5761
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition CLI11.hpp:6325
Option * get_option(std::string option_name)
Get an option by name (non-const version)
Definition CLI11.hpp:6859
bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition CLI11.hpp:6883
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition CLI11.hpp:6945
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
Definition CLI11.hpp:7747
bool check_name(std::string name_to_check) const
Check the name, case insensitive and underscore insensitive if set.
Definition CLI11.hpp:6995
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
Definition CLI11.hpp:5905
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
Definition CLI11.hpp:7316
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition CLI11.hpp:5319
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition CLI11.hpp:5829
startup_mode
Definition CLI11.hpp:5431
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition CLI11.hpp:6871
Option * add_flag(std::string flag_name, T &flag_count, std::string flag_description="")
Definition CLI11.hpp:6022
Option * get_help_ptr()
Get a pointer to the help flag.
Definition CLI11.hpp:6939
App * require_subcommand(int value)
Definition CLI11.hpp:6334
CLI::App_p get_subcommand_ptr(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
Definition CLI11.hpp:6270
std::size_t count_all() const
Definition CLI11.hpp:6304
CLI::App_p get_subcommand_ptr(int index=0) const
Get an owning pointer to subcommand by index.
Definition CLI11.hpp:6278
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition CLI11.hpp:5764
void _process_extras()
Throw an error if anything is left over and should not be.
Definition CLI11.hpp:7494
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
Definition CLI11.hpp:7339
App * get_subcommand(std::string subcom) const
Check to see if a subcommand is part of this command (text version)
Definition CLI11.hpp:6243
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
Definition CLI11.hpp:6812
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition CLI11.hpp:5376
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 CLI11.hpp:7068
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition CLI11.hpp:5612
App * parent_
A pointer to the parent if this is a subcommand.
Definition CLI11.hpp:5462
App * prefix_command(bool allow=true)
Do not parse anything after the first unrecognized option and return.
Definition CLI11.hpp:5688
App * group(std::string group_name)
Changes the group membership.
Definition CLI11.hpp:6319
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
Definition CLI11.hpp:7156
bool get_ignore_case() const
Check the status of ignore_case.
Definition CLI11.hpp:6874
bool got_subcommand(std::string subcommand_name) const
Check with name instead of pointer to see if subcommand was selected.
Definition CLI11.hpp:6608
virtual void pre_callback()
Definition CLI11.hpp:6400
void parse(int argc, const char *const *argv)
Definition CLI11.hpp:6424
T * add_option_group(std::string group_name, std::string group_description="")
creates an option group as part of the given app
Definition CLI11.hpp:6166
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition CLI11.hpp:6960
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition CLI11.hpp:6005
bool get_prefix_command() const
Get the prefix command status.
Definition CLI11.hpp:6910
const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition CLI11.hpp:7038
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 CLI11.hpp:5521
const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition CLI11.hpp:6969
const Option * get_config_ptr() const
Get a pointer to the config option. (const)
Definition CLI11.hpp:6951
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 CLI11.hpp:6260
App * allow_windows_style_options(bool value=true)
Definition CLI11.hpp:5710
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 CLI11.hpp:5871
std::vector< App * > get_subcommands() const
Definition CLI11.hpp:6564
void clear()
Reset the parsed data.
Definition CLI11.hpp:6407
std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Definition CLI11.hpp:7720
App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Definition CLI11.hpp:7848
const std::string & get_group() const
Get the group of this subcommand.
Definition CLI11.hpp:6892
bool remove_needs(App *app)
Removes a subcommand from the needs list of this subcommand.
Definition CLI11.hpp:6687
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type)
Definition CLI11.hpp:7900
bool get_required() const
Get the status of required.
Definition CLI11.hpp:6916
bool get_validate_positionals() const
Get the status of validating positionals.
Definition CLI11.hpp:6933
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 CLI11.hpp:6521
const Option * get_version_ptr() const
Get a pointer to the version option. (const)
Definition CLI11.hpp:6957
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
Definition CLI11.hpp:5569
std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition CLI11.hpp:6901
bool get_disabled() const
Get the status of disabled.
Definition CLI11.hpp:6919
void _process_config_file()
Read and process a configuration file (main app only)
Definition CLI11.hpp:7223
std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
Definition CLI11.hpp:7075
App * enabled_by_default(bool enable=true)
Definition CLI11.hpp:5641
void _process_extras(std::vector< std::string > &args)
Definition CLI11.hpp:7510
App * footer(std::string footer_string)
Set footer.
Definition CLI11.hpp:6701
App * needs(Option *opt)
Definition CLI11.hpp:6635
App * require_option(int value)
Definition CLI11.hpp:6363
std::vector< App * > get_subcommands(const std::function< bool(App *)> &filter)
Definition CLI11.hpp:6586
virtual ~App()=default
virtual destructor
bool get_allow_extras() const
Get the status of allow extras.
Definition CLI11.hpp:6913
std::vector< Option_p > options_
The list of options, stored locally.
Definition CLI11.hpp:5345
void parse(std::vector< std::string > &args)
Definition CLI11.hpp:6471
std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition CLI11.hpp:6754
std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition CLI11.hpp:6560
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition CLI11.hpp:6183
App * get_subcommand(int index=0) const
Get a pointer to subcommand by index.
Definition CLI11.hpp:6250
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition CLI11.hpp:5784
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition CLI11.hpp:6354
void parse(std::vector< std::string > &&args)
The real work is done here. Expects a reversed vector.
Definition CLI11.hpp:6491
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition CLI11.hpp:5563
App * add_subcommand(CLI::App_p subcom)
Add a previously created app as a subcommand.
Definition CLI11.hpp:6202
Option * add_flag(std::string flag_name, T &flag_description)
Definition CLI11.hpp:6013
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
Definition CLI11.hpp:6655
void parse_from_stream(std::istream &input)
Definition CLI11.hpp:6510
App * parse_complete_callback(std::function< void()> pc_callback)
Definition CLI11.hpp:5556
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition CLI11.hpp:5749
App * description(std::string app_description)
Set the description of the app.
Definition CLI11.hpp:6773
const Option * get_option_no_throw(std::string option_name) const noexcept
Get an option by name (noexcept const version)
Definition CLI11.hpp:6831
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 CLI11.hpp:5922
std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition CLI11.hpp:6978
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition CLI11.hpp:6620
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Definition CLI11.hpp:5483
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
Definition CLI11.hpp:6677
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
Definition CLI11.hpp:8159
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 CLI11.hpp:6526
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 CLI11.hpp:8091
std::vector< const App * > get_subcommands(const std::function< bool(const App *)> &filter) const
Definition CLI11.hpp:6568
Option * get_version_ptr()
Get a pointer to the version option.
Definition CLI11.hpp:6954
const Option * get_help_ptr() const
Get a pointer to the help flag. (const)
Definition CLI11.hpp:6942
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 CLI11.hpp:6076
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 CLI11.hpp:6779
bool get_silent() const
Get the status of silence.
Definition CLI11.hpp:6922
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition CLI11.hpp:5468
void _parse_stream(std::istream &input)
Internal function to parse a stream.
Definition CLI11.hpp:7580
std::string get_description() const
Get the app or subcommand description.
Definition CLI11.hpp:6770
bool get_fallthrough() const
Check the status of fallthrough.
Definition CLI11.hpp:6880
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition CLI11.hpp:5390
Option * add_flag(std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
Vector version to capture multiple flags.
Definition CLI11.hpp:6059
std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition CLI11.hpp:6757
std::size_t get_require_option_max() const
Get the required max option value.
Definition CLI11.hpp:6907
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 CLI11.hpp:6116
App * final_callback(std::function< void()> app_callback)
Definition CLI11.hpp:5549
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition CLI11.hpp:5665
std::size_t count() const
Definition CLI11.hpp:6300
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition CLI11.hpp:6706
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition CLI11.hpp:6611
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Definition CLI11.hpp:5728
std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition CLI11.hpp:6712
std::string version() const
Displays a version string.
Definition CLI11.hpp:6733
void _configure()
Definition CLI11.hpp:7135
const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version)
Definition CLI11.hpp:6963
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
Definition CLI11.hpp:6216
App * get_subcommand(const App *subcom) const
Definition CLI11.hpp:6233
std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition CLI11.hpp:6760
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition CLI11.hpp:6602
const Option * get_option(std::string option_name) const
Get an option by name.
Definition CLI11.hpp:6850
std::string get_footer() const
Generate and return the footer.
Definition CLI11.hpp:6895
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition CLI11.hpp:5716
App * alias(std::string app_name)
Set an alias for the app.
Definition CLI11.hpp:5587
bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition CLI11.hpp:6877
std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
Definition CLI11.hpp:7041
void _process_callbacks()
Process callbacks. Runs on all subcommands.
Definition CLI11.hpp:7289
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition CLI11.hpp:5743
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 CLI11.hpp:7196
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition CLI11.hpp:5900
const std::string & get_name() const
Get the name of the current app.
Definition CLI11.hpp:6966
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
Definition CLI11.hpp:8060
void _validate() const
Definition CLI11.hpp:7096
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition CLI11.hpp:5682
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition CLI11.hpp:6045
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
Definition CLI11.hpp:7526
config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition CLI11.hpp:6936
App & operator=(const App &)=delete
App * require_option(std::size_t min, std::size_t max)
Definition CLI11.hpp:6376
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
Definition CLI11.hpp:5652
std::vector< Option * > get_options(const std::function< bool(Option *)> filter={})
Non-const version of the above.
Definition CLI11.hpp:6796
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition CLI11.hpp:7024
bool _has_remaining_positionals() const
Count the required remaining positional arguments.
Definition CLI11.hpp:7734
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 CLI11.hpp:6092
bool _parse_subcommand(std::vector< std::string > &args)
Definition CLI11.hpp:7870
bool get_enabled_by_default() const
Get the status of disabled by default.
Definition CLI11.hpp:6931
void _parse_config(const std::vector< ConfigItem > &args)
Definition CLI11.hpp:7595
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition CLI11.hpp:5618
App * callback(std::function< void()> app_callback)
Definition CLI11.hpp:5538
bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition CLI11.hpp:6886
std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition CLI11.hpp:6898
App * needs(App *app)
Definition CLI11.hpp:6643
App * require_subcommand(std::size_t min, std::size_t max)
Definition CLI11.hpp:6347
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
Definition CLI11.hpp:8141
bool get_immediate_callback() const
Get the status of disabled.
Definition CLI11.hpp:6925
Thrown when the wrong number of arguments has been received.
Definition CLI11.hpp:782
static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received)
Definition CLI11.hpp:792
static ArgumentMismatch TypedAtLeast(std::string name, int num, std::string type)
Definition CLI11.hpp:800
static ArgumentMismatch AtMost(std::string name, int num, std::size_t received)
Definition CLI11.hpp:796
static ArgumentMismatch FlagOverride(std::string name)
Definition CLI11.hpp:803
Definition CLI11.hpp:3523
Options
Definition CLI11.hpp:3529
AsNumberWithUnit(std::map< std::string, Number > mapping, Options opts=DEFAULT, const std::string &unit_name="UNIT")
Definition CLI11.hpp:3538
Definition CLI11.hpp:3661
AsSizeValue(bool kb_is_1000)
Definition CLI11.hpp:3672
std::uint64_t result_t
Definition CLI11.hpp:3663
Thrown on construction of a bad name.
Definition CLI11.hpp:647
static BadNameString BadLongName(std::string name)
Definition CLI11.hpp:651
static BadNameString OneCharName(std::string name)
Definition CLI11.hpp:650
static BadNameString DashesOnly(std::string name)
Definition CLI11.hpp:652
static BadNameString MultiPositionalNames(std::string name)
Definition CLI11.hpp:655
Produce a bounded range (factory). Min and max are inclusive.
Definition CLI11.hpp:3125
Bound(T min_val, T max_val)
Definition CLI11.hpp:3131
Bound(T max_val)
Range of one value is 0 to value.
Definition CLI11.hpp:3152
Usually something like –help-all on command line.
Definition CLI11.hpp:695
-h or –help on command line
Definition CLI11.hpp:689
-v or –version on command line
Definition CLI11.hpp:702
This converter works with INI/TOML files; to write INI files use ConfigINI.
Definition CLI11.hpp:2583
const std::string & section() const
get the section
Definition CLI11.hpp:2653
std::vector< ConfigItem > from_config(std::istream &input) const override
Convert a configuration into an app.
Definition CLI11.hpp:8568
ConfigBase * comment(char cchar)
Specify the configuration for comment characters.
Definition CLI11.hpp:2614
ConfigBase * arrayDelimiter(char aSep)
Specify the delimiter character for an array.
Definition CLI11.hpp:2625
ConfigBase * quoteCharacter(char qString, char qChar)
Specify the quote characters used around strings and characters.
Definition CLI11.hpp:2635
std::string & sectionRef()
get a reference to the configuration section
Definition CLI11.hpp:2651
ConfigBase * arrayBounds(char aStart, char aEnd)
Specify the start and end characters for an array.
Definition CLI11.hpp:2619
std::string to_config(const App *, bool default_also, bool write_description, std::string prefix) const override
Convert an app into a configuration.
Definition CLI11.hpp:8701
int16_t index() const
get the section index
Definition CLI11.hpp:2663
ConfigBase * maxLayers(uint8_t layers)
Specify the maximum number of parents.
Definition CLI11.hpp:2641
ConfigBase * section(const std::string §ionName)
specify a particular section of the configuration file to use
Definition CLI11.hpp:2655
ConfigBase * valueSeparator(char vSep)
Specify the delimiter between a name and value.
Definition CLI11.hpp:2630
ConfigBase * index(int16_t sectionIndex)
specify a particular index in the section to use (-1) for all sections to use
Definition CLI11.hpp:2665
int16_t & indexRef()
get a reference to the configuration index
Definition CLI11.hpp:2661
ConfigBase * parentSeparator(char sep)
Specify the separator to use for parent layers.
Definition CLI11.hpp:2646
Thrown when extra values are found in an INI file.
Definition CLI11.hpp:839
static ConfigError NotConfigurable(std::string item)
Definition CLI11.hpp:843
static ConfigError Extras(std::string item)
Definition CLI11.hpp:842
ConfigINI generates a "standard" INI compliant output.
Definition CLI11.hpp:2675
ConfigINI()
Definition CLI11.hpp:2678
This class provides a converter for configuration files.
Definition CLI11.hpp:2550
std::vector< ConfigItem > from_file(const std::string &name)
Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure.
Definition CLI11.hpp:2570
virtual std::string to_config(const App *, bool, bool, std::string) const =0
Convert an app into a configuration.
virtual ~Config()=default
Virtual destructor.
virtual std::vector< ConfigItem > from_config(std::istream &) const =0
Convert a configuration into an app.
virtual std::string to_flag(const ConfigItem &item) const
Get a flag value.
Definition CLI11.hpp:2562
Construction errors (not in parsing)
Definition CLI11.hpp:614
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition CLI11.hpp:722
static ConversionError TrueFalse(std::string name)
Definition CLI11.hpp:732
ConversionError(std::string name, std::vector< std::string > results)
Definition CLI11.hpp:727
static ConversionError TooManyInputsFlag(std::string name)
Definition CLI11.hpp:729
Class wrapping some of the accessors of Validator.
Definition CLI11.hpp:2910
All errors derive from this one.
Definition CLI11.hpp:596
int get_exit_code() const
Definition CLI11.hpp:601
Error(std::string name, std::string msg, ExitCodes exit_code)
Definition CLI11.hpp:608
std::string get_name() const
Definition CLI11.hpp:603
Error(std::string name, std::string msg, int exit_code=static_cast< int >(ExitCodes::BaseClass))
Definition CLI11.hpp:605
Thrown when an excludes option is present.
Definition CLI11.hpp:816
Thrown when parsing an INI file and it is missing.
Definition CLI11.hpp:715
static FileError Missing(std::string name)
Definition CLI11.hpp:718
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition CLI11.hpp:619
static IncorrectConstruction SetFlag(std::string name)
Definition CLI11.hpp:628
static IncorrectConstruction MultiOptionPolicy(std::string name)
Definition CLI11.hpp:641
static IncorrectConstruction AfterMultiOpt(std::string name)
Definition CLI11.hpp:634
static IncorrectConstruction MissingOption(std::string name)
Definition CLI11.hpp:638
static IncorrectConstruction PositionalFlag(std::string name)
Definition CLI11.hpp:622
static IncorrectConstruction Set0Opt(std::string name)
Definition CLI11.hpp:625
static IncorrectConstruction ChangeNotVector(std::string name)
Definition CLI11.hpp:631
Thrown when validation fails before parsing.
Definition CLI11.hpp:849
Verify items are in a set.
Definition CLI11.hpp:3297
IsMember(T &&set)
This checks to see if an item is in a set (empty function)
Definition CLI11.hpp:3307
IsMember(T set, F filter_function)
Definition CLI11.hpp:3311
IsMember(T &&set, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&...other)
You can pass in as many filter functions as you like, they nest (string only currently)
Definition CLI11.hpp:3355
IsMember(std::initializer_list< T > values, Args &&...args)
This allows in-place construction using an initializer list.
Definition CLI11.hpp:3303
std::function< std::string(std::string)> filter_fn_t
Definition CLI11.hpp:3299
Thrown when an option already exists.
Definition CLI11.hpp:661
static OptionAlreadyAdded Excludes(std::string name, std::string other)
Definition CLI11.hpp:668
static OptionAlreadyAdded Requires(std::string name, std::string other)
Definition CLI11.hpp:665
Definition CLI11.hpp:3952
bool get_disable_flag_override() const
The status of configurable.
Definition CLI11.hpp:4040
CRTP * mandatory(bool value=true)
Support Plumbum term.
Definition CLI11.hpp:4015
CRTP * take_all()
Set the multi option policy to take all arguments.
Definition CLI11.hpp:4068
bool get_ignore_case() const
The status of ignore case.
Definition CLI11.hpp:4031
bool get_configurable() const
The status of configurable.
Definition CLI11.hpp:4037
CRTP * group(const std::string &name)
Changes the group membership.
Definition CLI11.hpp:4000
CRTP * join()
Set the multi option policy to join.
Definition CLI11.hpp:4075
CRTP * join(char delim)
Set the multi option policy to join with a specific delimiter.
Definition CLI11.hpp:4082
bool get_ignore_underscore() const
The status of ignore_underscore.
Definition CLI11.hpp:4034
CRTP * take_first()
Set the multi option policy to take last.
Definition CLI11.hpp:4061
CRTP * configurable(bool value=true)
Allow in a configuration file.
Definition CLI11.hpp:4090
CRTP * delimiter(char value='\0')
Allow in a configuration file.
Definition CLI11.hpp:4096
MultiOptionPolicy get_multi_option_policy() const
The status of the multi option policy.
Definition CLI11.hpp:4049
bool get_required() const
True if this is a required option.
Definition CLI11.hpp:4028
bool required_
True if this is a required option.
Definition CLI11.hpp:3960
CRTP * take_last()
Set the multi option policy to take last.
Definition CLI11.hpp:4054
CRTP * always_capture_default(bool value=true)
Definition CLI11.hpp:4017
bool get_always_capture_default() const
Return true if this will automatically capture the default value for help printing.
Definition CLI11.hpp:4046
char get_delimiter() const
Get the current delimiter char.
Definition CLI11.hpp:4043
const std::string & get_group() const
Get the group of this option.
Definition CLI11.hpp:4025
void copy_to(T *other) const
Copy the contents to another similar class (one based on OptionBase)
Definition CLI11.hpp:3984
CRTP * required(bool value=true)
Set the option as required.
Definition CLI11.hpp:4009
Definition CLI11.hpp:4104
OptionDefaults * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times.
Definition CLI11.hpp:4111
OptionDefaults * ignore_case(bool value=true)
Ignore the case of the option name.
Definition CLI11.hpp:4117
OptionDefaults * ignore_underscore(bool value=true)
Ignore underscores in the option name.
Definition CLI11.hpp:4123
OptionDefaults * delimiter(char value='\0')
set a delimiter character to split up single arguments to treat as multiple inputs
Definition CLI11.hpp:4135
OptionDefaults * disable_flag_override(bool value=true)
Disable overriding flag values with an '=' segment.
Definition CLI11.hpp:4129
Thrown when counting a non-existent option.
Definition CLI11.hpp:866
Extension of App to better manage groups of options.
Definition CLI11.hpp:8200
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition CLI11.hpp:8225
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition CLI11.hpp:8209
Option_group(std::string group_description, std::string group_name, App *parent)
Definition CLI11.hpp:8202
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition CLI11.hpp:8219
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition CLI11.hpp:8217
Definition CLI11.hpp:4141
const std::string & get_option_text() const
Definition CLI11.hpp:4676
const std::vector< std::string > & get_lnames() const
Get the long names.
Definition CLI11.hpp:4614
int get_type_size_max() const
The maximum number of arguments the option expects.
Definition CLI11.hpp:4593
std::size_t count() const
Count the total number of times an option was passed.
Definition CLI11.hpp:4267
int get_expected_min() const
The number of times the option expects to be included.
Definition CLI11.hpp:4638
Option * excludes(Option *opt)
Sets excluded options.
Definition CLI11.hpp:4468
bool get_run_callback_for_default() const
Get the current value of run_callback_for_default.
Definition CLI11.hpp:4357
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition CLI11.hpp:4986
int get_expected_max() const
The max number of times the option expects to be included.
Definition CLI11.hpp:4640
option_state
enumeration for the option state machine
Definition CLI11.hpp:4231
bool get_trigger_on_parse() const
The status of trigger on parse.
Definition CLI11.hpp:4340
int get_expected() const
The number of times the option expects to be included.
Definition CLI11.hpp:4635
const results_t & results() const
Get the current complete results set.
Definition CLI11.hpp:4913
results_t reduced_results() const
Get a copy of the results.
Definition CLI11.hpp:4916
Option(std::string option_name, std::string option_description, callback_t callback, App *parent)
Making an option by hand is not defined, it must be made by the App class.
Definition CLI11.hpp:4254
Option * expected(int value_min, int value_max)
Set the range of expected arguments.
Definition CLI11.hpp:4308
int get_type_size_min() const
The minimum number of arguments the option expects.
Definition CLI11.hpp:4591
Option * ignore_case(bool value=true)
Definition CLI11.hpp:4519
std::string get_default_str() const
The default value (for help printing)
Definition CLI11.hpp:4608
std::set< Option * > needs_
A list of options that are required with this option.
Definition CLI11.hpp:4207
Option * default_function(const std::function< std::string()> &func)
Set a capture function for the default. Mostly used by App.
Definition CLI11.hpp:5039
bool remove_excludes(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
Definition CLI11.hpp:4499
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
Definition CLI11.hpp:4565
bool check_lname(std::string name) const
Requires "--" to be removed from string.
Definition CLI11.hpp:4832
Option * add_result(std::string s)
Puts a result at the end.
Definition CLI11.hpp:4890
std::set< Option * > excludes_
A list of options that are excluded with this option.
Definition CLI11.hpp:4210
Option & operator=(const Option &)=delete
bool check_fname(std::string name) const
Requires "--" to be removed from string.
Definition CLI11.hpp:4837
std::string get_flag_value(const std::string &name, std::string input_value) const
Definition CLI11.hpp:4846
const std::vector< std::string > & get_fnames() const
Get the flag names with specified default values.
Definition CLI11.hpp:4620
Option * each(const std::function< void(std::string)> &func)
Adds a user supplied function to run on each item passed in (communicate though lambda capture)
Definition CLI11.hpp:4402
Validator * get_validator(const std::string &Validator_name="")
Get a named Validator.
Definition CLI11.hpp:4412
Option * option_text(std::string text)
Definition CLI11.hpp:4671
Option * check(std::function< std::string(const std::string &)> Validator, std::string Validator_description="", std::string Validator_name="")
Adds a Validator. Takes a const string& and returns an error message (empty if conversion/check is ok...
Definition CLI11.hpp:4369
const std::string & get_description() const
Get the description.
Definition CLI11.hpp:4663
Option * expected(int value)
Set the number of expected arguments.
Definition CLI11.hpp:4286
bool has_description() const
True if option has description.
Definition CLI11.hpp:4660
bool check_name(const std::string &name) const
Check a name. Requires "-" or "--" for short / long, supports positional name.
Definition CLI11.hpp:4797
Option(const Option &)=delete
bool get_force_callback() const
The status of force_callback.
Definition CLI11.hpp:4348
bool get_allow_extra_args() const
Get the current value of allow extra args.
Definition CLI11.hpp:4333
Option * disable_flag_override(bool value=true)
Disable flag overrides values, e.g. –flag=is not allowed.
Definition CLI11.hpp:4579
std::vector< std::string > snames_
A list of the short names (-a) without the leading dashes.
Definition CLI11.hpp:4149
Option * run_callback_for_default(bool value=true)
Definition CLI11.hpp:4352
Option * type_size(int option_type_size_min, int option_type_size_max)
Set a custom option type size range.
Definition CLI11.hpp:5011
void inject_separator(bool value=true)
Set the value of the separator injection flag.
Definition CLI11.hpp:5036
Option * allow_extra_args(bool value=true)
Definition CLI11.hpp:4328
std::set< Option * > get_excludes() const
The set of options excluded.
Definition CLI11.hpp:4605
Option * trigger_on_parse(bool value=true)
Set the value of trigger_on_parse which specifies that the option callback should be triggered on eve...
Definition CLI11.hpp:4335
int get_type_size() const
The number of arguments the option expects.
Definition CLI11.hpp:4588
Option * type_size(int option_type_size)
Set a custom option size.
Definition CLI11.hpp:4992
callback_t get_callback() const
Get the callback function.
Definition CLI11.hpp:4611
std::string get_type_name() const
Get the full typename for this option.
Definition CLI11.hpp:5087
bool nonpositional() const
True if option has at least one non-positional name.
Definition CLI11.hpp:4657
std::string get_envname() const
The environment variable associated to this value.
Definition CLI11.hpp:4599
int get_items_expected_max() const
Get the maximum number of items expected to be returned and used for the callback.
Definition CLI11.hpp:4646
Option * transform(const std::function< std::string(std::string)> &func, std::string transform_description="", std::string transform_name="")
Adds a Validator-like function that can change result.
Definition CLI11.hpp:4386
Option * excludes(std::string opt_name)
Can find a string if needed.
Definition CLI11.hpp:4484
int get_inject_separator() const
Return the inject_separator flag.
Definition CLI11.hpp:4596
bool remove_needs(Option *opt)
Remove needs link from an option. Returns true if the option really was in the needs list.
Definition CLI11.hpp:4457
bool get_callback_run() const
See if the callback has been run already.
Definition CLI11.hpp:4973
T as() const
Return the results as the specified type.
Definition CLI11.hpp:4966
void run_callback()
Process the callback.
Definition CLI11.hpp:4746
Option * transform(Validator Validator, const std::string &Validator_name="")
Adds a transforming Validator with a built in type name.
Definition CLI11.hpp:4378
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 CLI11.hpp:4686
void clear()
Clear the parsed results (mostly for testing)
Definition CLI11.hpp:4276
Option * add_result(std::vector< std::string > s)
Puts a result at the end.
Definition CLI11.hpp:4904
Option * capture_default_str()
Capture the default value from the original value (if it can be captured)
Definition CLI11.hpp:5045
void results(T &output) const
Get the results as a specified type.
Definition CLI11.hpp:4935
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value)
Definition CLI11.hpp:5053
bool get_positional() const
True if the argument can be given directly.
Definition CLI11.hpp:4654
std::string envname_
If given, check the environment for this option.
Definition CLI11.hpp:4165
std::set< Option * > get_needs() const
The set of options needed.
Definition CLI11.hpp:4602
bool check_sname(std::string name) const
Requires "-" to be removed from string.
Definition CLI11.hpp:4827
Option * ignore_underscore(bool value=true)
Definition CLI11.hpp:4543
std::vector< std::pair< std::string, std::string > > default_flag_values_
Definition CLI11.hpp:4156
Option * envname(std::string name)
Sets environment variable to read if no option given.
Definition CLI11.hpp:4510
Option * type_name_fn(std::function< std::string()> typefun)
Set the type function to run when displayed on this option.
Definition CLI11.hpp:4980
Option * default_val(const X &val)
Definition CLI11.hpp:5060
Option * add_result(std::string s, int &results_added)
Puts a result at the end and get a count of the number of arguments actually added.
Definition CLI11.hpp:4897
const std::string & get_single_name() const
Get a single name for the option, first of lname, pname, sname, envname.
Definition CLI11.hpp:4622
Option * needs(Option *opt)
Sets required options.
Definition CLI11.hpp:4434
const std::string & matching_name(const Option &other) const
If options share any of the same names, find it.
Definition CLI11.hpp:4773
Option * needs(A opt, B opt1, ARG... args)
Any number supported, any mix of string and Opt.
Definition CLI11.hpp:4451
Option * description(std::string option_description)
Set the description.
Definition CLI11.hpp:4666
std::vector< std::string > lnames_
A list of the long names (--long) without the leading dashes.
Definition CLI11.hpp:4152
Option * force_callback(bool value=true)
Set the value of force_callback.
Definition CLI11.hpp:4343
Validator * get_validator(int index)
Get a Validator by index NOTE: this may not be the order of definition.
Definition CLI11.hpp:4425
bool operator==(const Option &other) const
If options share any of the same names, they are equal (not counting positional)
Definition CLI11.hpp:4794
Option * check(Validator validator, const std::string &validator_name="")
Adds a Validator with a built in type name.
Definition CLI11.hpp:4360
Option * needs(std::string opt_name)
Can find a string if needed.
Definition CLI11.hpp:4442
bool empty() const
True if the option was not passed.
Definition CLI11.hpp:4270
int get_items_expected_min() const
The total min number of expected string values to be used.
Definition CLI11.hpp:4643
Option * excludes(A opt, B opt1, ARG... args)
Any number supported, any mix of string and Opt.
Definition CLI11.hpp:4493
const std::vector< std::string > & get_snames() const
Get the short names.
Definition CLI11.hpp:4617
int get_items_expected() const
The total min number of expected string values to be used.
Definition CLI11.hpp:4651
Anything that can error in Parse.
Definition CLI11.hpp:676
Produce a range (factory). Min and max are inclusive.
Definition CLI11.hpp:3087
Range(T min_val, T max_val, const std::string &validator_name=std::string{})
Definition CLI11.hpp:3094
Range(T max_val, const std::string &validator_name=std::string{})
Range of one value is 0 to value.
Definition CLI11.hpp:3114
Thrown when a required option is missing.
Definition CLI11.hpp:745
static RequiredError Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list)
Definition CLI11.hpp:756
static RequiredError Subcommand(std::size_t min_subcom)
Definition CLI11.hpp:748
Thrown when a requires option is missing.
Definition CLI11.hpp:809
Does not output a diagnostic in CLI11_PARSE, but allows main() to return with a specific error code.
Definition CLI11.hpp:709
This is a successful completion on parsing, supposed to exit.
Definition CLI11.hpp:683
Validate the input as a particular type.
Definition CLI11.hpp:3069
TypeValidator()
Definition CLI11.hpp:3080
TypeValidator(const std::string &validator_name)
Definition CLI11.hpp:3071
Thrown when validation of results fails.
Definition CLI11.hpp:738
Some validators that are provided.
Definition CLI11.hpp:2701
bool get_active() const
Get a boolean if the validator is active.
Definition CLI11.hpp:2815
int application_index_
A Validator will only apply to an indexed value (-1 is all elements)
Definition CLI11.hpp:2712
Validator & non_modifying(bool no_modify=true)
Specify whether the Validator can be modifying or not.
Definition CLI11.hpp:2797
Validator & description(std::string validator_desc)
Specify the type string.
Definition CLI11.hpp:2754
std::string operator()(const std::string &str) const
Definition CLI11.hpp:2748
Validator operator&(const Validator &other) const
Definition CLI11.hpp:2822
bool active_
Enable for Validator to allow it to be disabled if need be.
Definition CLI11.hpp:2714
Validator name(std::string validator_name) const
Specify the type string.
Definition CLI11.hpp:2777
Validator application_index(int app_index) const
Specify the application index of a validator.
Definition CLI11.hpp:2807
const std::string & get_name() const
Get the name of the Validator.
Definition CLI11.hpp:2783
Validator(std::string validator_desc)
Construct a Validator with just the description string.
Definition CLI11.hpp:2721
std::string get_description() const
Generate type description information for the Validator.
Definition CLI11.hpp:2765
Validator & name(std::string validator_name)
Specify the type string.
Definition CLI11.hpp:2772
std::string operator()(std::string &str) const
Definition CLI11.hpp:2733
Validator active(bool active_val=true) const
Specify whether the Validator is active or not.
Definition CLI11.hpp:2790
std::function< std::string()> desc_function_
This is the description function, if empty the description_ will be used.
Definition CLI11.hpp:2704
int get_application_index() const
Get the current value of the application index.
Definition CLI11.hpp:2813
std::function< std::string(std::string &)> func_
Definition CLI11.hpp:2708
Validator operator!() const
Create a validator that fails when a given validator succeeds.
Definition CLI11.hpp:2870
Validator operator|(const Validator &other) const
Definition CLI11.hpp:2847
Validator & active(bool active_val=true)
Specify whether the Validator is active or not.
Definition CLI11.hpp:2785
std::string name_
The name for search purposes of the Validator.
Definition CLI11.hpp:2710
Validator description(std::string validator_desc) const
Specify the type string.
Definition CLI11.hpp:2759
bool get_modifying() const
Get a boolean if the validator is allowed to modify the input returns true if it can modify the input...
Definition CLI11.hpp:2818
Validator & application_index(int app_index)
Specify the application index of a validator.
Definition CLI11.hpp:2802
Validator(std::function< std::string(std::string &)> op, std::string validator_desc, std::string validator_name="")
Construct Validator from basic information.
Definition CLI11.hpp:2723
Validator & operation(std::function< std::string(std::string &)> op)
Set the Validator operation function.
Definition CLI11.hpp:2727
Check for an existing directory (returns error message if check fails)
Definition CLI11.hpp:2981
ExistingDirectoryValidator()
Definition CLI11.hpp:2983
Check for an existing file (returns error message if check fails)
Definition CLI11.hpp:2964
ExistingFileValidator()
Definition CLI11.hpp:2966
Check for an existing path.
Definition CLI11.hpp:2998
ExistingPathValidator()
Definition CLI11.hpp:3000
Validate the given string is a legal ipv4 address.
Definition CLI11.hpp:3026
IPV4Validator()
Definition CLI11.hpp:3028
Check for an non-existing path.
Definition CLI11.hpp:3012
NonexistentPathValidator()
Definition CLI11.hpp:3014
Check for complex.
Definition CLI11.hpp:1049
Check for input streamability.
Definition CLI11.hpp:1038
Definition CLI11.hpp:1027
Definition CLI11.hpp:1111
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 CLI11.hpp:8375
std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+)
Definition CLI11.hpp:8356
std::vector< std::string > split_names(std::string current)
Definition CLI11.hpp:2450
std::string & remove_quotes(std::string &str)
remove quotes at the front and back of a string either '"' or '\''
Definition CLI11.hpp:268
constexpr enabler dummy
An instance to use in EnableIf.
Definition CLI11.hpp:888
std::string & add_quotes_if_needed(std::string &str)
Add quotes if the string contains spaces.
Definition CLI11.hpp:533
std::string ini_join(const std::vector< std::string > &args, char sepChar=',', char arrayStart='[', char arrayEnd=']', char stringQuote='"', char characterQuote = '\'')
Comma separated join, adds quotes if needed.
Definition CLI11.hpp:8467
auto smart_deref(T value) -> decltype(*value)
Definition CLI11.hpp:3158
bool split_long(const std::string ¤t, std::string &name, std::string &value)
Definition CLI11.hpp:2418
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 CLI11.hpp:1124
path_type check_path(const char *file) noexcept
get the type of the path from a file name
Definition CLI11.hpp:2948
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition CLI11.hpp:1177
bool split_short(const std::string ¤t, std::string &name, std::string &rest)
Definition CLI11.hpp:2408
path_type
CLI enumeration of different file types.
Definition CLI11.hpp:2919
std::string convert_arg_for_ini(const std::string &arg, char stringQuote='"', char characterQuote = '\'')
Definition CLI11.hpp:8422
std::tuple< std::vector< std::string >, std::vector< std::string >, std::string > get_names(const std::vector< std::string > &input)
Get a vector of short names, one of long names, and a single name.
Definition CLI11.hpp:2490
std::string generate_map(const T &map, bool key_only=false)
Generate a string representation of a map.
Definition CLI11.hpp:3182
std::string & rtrim(std::string &str)
Trim whitespace from right of string.
Definition CLI11.hpp:241
std::ptrdiff_t find_member(std::string name, const std::vector< std::string > names, bool ignore_case=false, bool ignore_underscore=false)
Check if a string is a member of a list of strings and optionally ignore case or ignore underscores.
Definition CLI11.hpp:422
bool valid_first_char(T c)
Definition CLI11.hpp:337
bool valid_name_string(const std::string &str)
Verify an option/subcommand name.
Definition CLI11.hpp:348
std::ostream & format_help(std::ostream &out, std::string name, const std::string &description, std::size_t wid)
Print a two part "help" string.
Definition CLI11.hpp:300
std::string remove_underscore(std::string str)
remove underscores from a string
Definition CLI11.hpp:385
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition CLI11.hpp:366
std::vector< std::string > split_up(std::string str, char delimiter='\0')
Definition CLI11.hpp:464
std::enable_if< std::is_signed< T >::value, T >::type overflowCheck(const T &a, const T &b)
Do a check for overflow on signed numbers.
Definition CLI11.hpp:3255
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 CLI11.hpp:3269
std::string find_and_modify(std::string str, std::string trigger, Callable modify)
Definition CLI11.hpp:454
std::string trim_copy(const std::string &str)
Make a copy of the string and then trim it.
Definition CLI11.hpp:262
std::string & trim(std::string &str)
Trim whitespace from string.
Definition CLI11.hpp:256
bool from_stream(const std::string &istring, T &obj)
Templated operation to get a value from a stream.
Definition CLI11.hpp:1061
std::string fix_newlines(const std::string &leader, std::string input)
Definition CLI11.hpp:282
void remove_default_flag_values(std::string &flags)
Definition CLI11.hpp:408
std::string generate_set(const T &set)
Generate a string representation of a set.
Definition CLI11.hpp:3169
std::ostream & format_aliases(std::ostream &out, const std::vector< std::string > &aliases, std::size_t wid)
Print subcommand aliases.
Definition CLI11.hpp:318
bool valid_later_char(T c)
Verify following characters of an option.
Definition CLI11.hpp:340
std::pair< std::string, std::string > split_program_name(std::string commandline)
Definition CLI11.hpp:3717
constexpr int expected_max_vector_size
Definition CLI11.hpp:161
std::string value_string(const T &value)
get a string as a convertible value for arithmetic types
Definition CLI11.hpp:1191
std::string & ltrim(std::string &str)
Trim whitespace from left of string.
Definition CLI11.hpp:227
auto search(const T &set, const V &val) -> std::pair< bool, decltype(std::begin(detail::smart_deref(set)))>
A search function.
Definition CLI11.hpp:3213
bool split_windows_style(const std::string ¤t, std::string &name, std::string &value)
Definition CLI11.hpp:2434
std::string type_name()
Print type name for tuples with 2 or more elements.
Definition CLI11.hpp:1628
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition CLI11.hpp:181
std::string find_and_replace(std::string str, std::string from, std::string to)
Find and replace a substring with another substring.
Definition CLI11.hpp:391
return str
Definition CLI11.hpp:1621
bool lexical_assign(const std::string &input, AssignTo &output)
Assign a value through lexical cast operations.
Definition CLI11.hpp:1941
Classifier
Definition CLI11.hpp:5264
std::vector< std::string > generate_parents(const std::string §ion, std::string &name, char parentSeparator)
Definition CLI11.hpp:8493
std::vector< std::string > split(const std::string &s, char delim)
Split a string by a delim.
Definition CLI11.hpp:164
std::size_t escape_detect(std::string &str, std::size_t offset)
Definition CLI11.hpp:520
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition CLI11.hpp:360
bool isalpha(const std::string &str)
Verify that str consists of letters only.
Definition CLI11.hpp:372
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition CLI11.hpp:377
bool has_default_flag_values(const std::string &flags)
check if the flag definitions has possible false flags
Definition CLI11.hpp:404
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 CLI11.hpp:2462
enabler
Simple empty scoped class.
Definition CLI11.hpp:885
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition CLI11.hpp:1717
void checkParentSegments(std::vector< ConfigItem > &output, const std::string ¤tSection, char parentSeparator)
assuming non default segments do a check on the close and open of the segments in a configItem struct...
Definition CLI11.hpp:8519
std::int64_t to_flag_value(std::string val)
Convert a flag into an integer value typically binary flags.
Definition CLI11.hpp:1670
bool integral_conversion(const std::string &input, T &output) noexcept
Convert to an unsigned integral.
Definition CLI11.hpp:1647
constexpr std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size()
0 if the index > tuple size
Definition CLI11.hpp:1275
std::string rjoin(const T &v, std::string delim=",")
Join a string in reverse order.
Definition CLI11.hpp:214
std::string ignore_case(std::string item)
Helper function to allow ignore_case to be passed to IsMember or Transform.
Definition CLI11.hpp:3500
std::string ignore_underscore(std::string item)
Helper function to allow ignore_underscore to be passed to IsMember or Transform.
Definition CLI11.hpp:3503
typename std::enable_if< B, T >::type enable_if_t
Definition CLI11.hpp:896
ExitCodes
Definition CLI11.hpp:567
const detail::ExistingDirectoryValidator ExistingDirectory
Check for an existing directory (returns error message if check fails)
Definition CLI11.hpp:3057
void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
Definition CLI11.hpp:8302
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition CLI11.hpp:5275
void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
Definition CLI11.hpp:8233
typename std::conditional< B, T, F >::type conditional_t
A copy of std::conditional_t from C++14 - same reasoning as enable_if_t, it does not hurt to redefine...
Definition CLI11.hpp:905
std::unique_ptr< Option > Option_p
Definition CLI11.hpp:3940
void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
Definition CLI11.hpp:8275
std::vector< std::string > results_t
Definition CLI11.hpp:3933
const detail::NonexistentPathValidator NonexistentPath
Check for an non-existing path.
Definition CLI11.hpp:3063
AppFormatMode
Definition CLI11.hpp:3776
@ Normal
The normal, detailed help.
@ All
A fully expanded help.
@ Sub
Used when printed as part of expanded subcommand.
MultiOptionPolicy
Enumeration of the multiOption Policy selection.
Definition CLI11.hpp:3942
@ TakeAll
just get all the passed argument regardless
@ TakeFirst
take only the first Expected number of arguments
@ Throw
Throw an error if any extra arguments were given.
@ TakeLast
take only the last Expected number of arguments
@ Join
merge all the arguments together into a single string via the delimiter character default(' ')
const detail::IPV4Validator ValidIPV4
Check for an IP4 address.
Definition CLI11.hpp:3066
const detail::ExistingPathValidator ExistingPath
Check for an existing path.
Definition CLI11.hpp:3060
std::vector< std::pair< std::string, T > > TransformPairs
definition of the default transformation object
Definition CLI11.hpp:3363
const detail::ExistingFileValidator ExistingFile
Check for existing file (returns error message if check fails)
Definition CLI11.hpp:3054
typename make_void< Ts... >::type void_t
A copy of std::void_t from C++17 - same reasoning as enable_if_t, it does not hurt to redefine.
Definition CLI11.hpp:902
const Range NonNegativeNumber((std::numeric_limits< double >::max)(), "NONNEGATIVE")
Check for a non negative number.
std::function< bool(const results_t &)> callback_t
callback function definition
Definition CLI11.hpp:3935
std::string ignore_space(std::string item)
Helper function to allow checks to ignore spaces to be passed to IsMember or Transform.
Definition CLI11.hpp:3506
const Range PositiveNumber((std::numeric_limits< double >::min)(),(std::numeric_limits< double >::max)(), "POSITIVE")
Check for a positive valued number (val>0.0), min() her is the smallest positive number.
const TypeValidator< double > Number("NUMBER")
Check for a number.
std::shared_ptr< App > App_p
Definition CLI11.hpp:5279
void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
Definition CLI11.hpp:8254
@ I
Definition AngularMomentum.hpp:15
directory_iterator end(const directory_iterator &) noexcept
Definition filesystem.hpp:5858
Holds values to load into Options.
Definition CLI11.hpp:2531
std::vector< std::string > inputs
Listing of inputs.
Definition CLI11.hpp:2539
std::string name
This is the name.
Definition CLI11.hpp:2536
std::vector< std::string > parents
This is the list of parents.
Definition CLI11.hpp:2533
std::string fullname() const
The list of parents and name joined by ".".
Definition CLI11.hpp:2542
std::string type
Definition CLI11.hpp:931
This can be specialized to override the type deduction for IsMember.
Definition CLI11.hpp:928
T type
Definition CLI11.hpp:928
This class is simply to allow tests access to App's protected functions.
Definition CLI11.hpp:8385
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 CLI11.hpp:8407
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition CLI11.hpp:8413
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 CLI11.hpp:8400
typename std::pointer_traits< T >::element_type type
Definition CLI11.hpp:944
not a pointer
Definition CLI11.hpp:941
T type
Definition CLI11.hpp:941
typename element_type< T >::type::value_type type
Definition CLI11.hpp:949
Definition CLI11.hpp:3202
std::integral_constant< bool, value > type
Definition CLI11.hpp:3208
static auto test(int) -> decltype(std::declval< CC >().find(std::declval< VV >()), std::true_type())
static auto test(...) -> decltype(std::false_type())
Definition CLI11.hpp:1074
Definition CLI11.hpp:1092
Definition CLI11.hpp:1104
typename std::remove_const< typename value_type::first_type >::type first_type
Definition CLI11.hpp:975
static auto first(Q &&pair_value) -> decltype(std::get< 0 >(std::forward< Q >(pair_value)))
Get the first value (really just the underlying value)
Definition CLI11.hpp:979
static auto second(Q &&pair_value) -> decltype(std::get< 1 >(std::forward< Q >(pair_value)))
Get the second value (really just the underlying value)
Definition CLI11.hpp:983
typename T::value_type value_type
Definition CLI11.hpp:974
typename std::remove_const< typename value_type::second_type >::type second_type
Definition CLI11.hpp:976
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition CLI11.hpp:952
typename T::value_type value_type
Definition CLI11.hpp:953
typename std::remove_const< value_type >::type second_type
Definition CLI11.hpp:955
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value)
Definition CLI11.hpp:962
typename std::remove_const< value_type >::type first_type
Definition CLI11.hpp:954
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value)
Definition CLI11.hpp:958
forward declare the subtype_count_min structure
Definition CLI11.hpp:1242
Set of overloads to get the type size of an object.
Definition CLI11.hpp:1239
This will only trigger for actual void type.
Definition CLI11.hpp:1215
This will only trigger for actual void type.
Definition CLI11.hpp:1245
typename T::value_type type
Definition CLI11.hpp:1211
template to get the underlying value type if it exists or use a default
Definition CLI11.hpp:1207
def type
Definition CLI11.hpp:1207
Check to see if something is bool (fail check by default)
Definition CLI11.hpp:908
Check to see if something is copyable pointer.
Definition CLI11.hpp:923
Check to see if something is a shared pointer.
Definition CLI11.hpp:914
A copy of std::void_t from C++17 (helper for C++11 and C++14)
Definition CLI11.hpp:899
void type
Definition CLI11.hpp:899