21#include "StringTools.hpp" 
   28#define CLI11_ERROR_DEF(parent, name)                                                                                  \ 
   30    name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {}   \ 
   31    name(std::string ename, std::string msg, ExitCodes exit_code)                                                      \ 
   32        : parent(std::move(ename), std::move(msg), exit_code) {}                                                       \ 
   35    name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {}                           \ 
   36    name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} 
   39#define CLI11_ERROR_SIMPLE(name)                                                                                       \ 
   40    explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {} 
   44enum class ExitCodes : 
int {
 
   46    IncorrectConstruction = 100,
 
   73class Error : 
public std::runtime_error {
 
   75    std::string error_name{
"Error"};
 
   78    CLI11_NODISCARD 
int get_exit_code()
 const { 
return actual_exit_code; }
 
   80    CLI11_NODISCARD std::string get_name()
 const { 
return error_name; }
 
   82    Error(std::string name, std::string msg, 
int exit_code = 
static_cast<int>(ExitCodes::BaseClass))
 
   83        : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {}
 
   85    Error(std::string name, std::string msg, ExitCodes exit_code) : 
Error(name, msg, 
static_cast<int>(exit_code)) {}
 
 
  113            name + 
": You can't change expected arguments after you've changed the multi option policy!");
 
  119        return IncorrectConstruction(name + 
": multi_option_policy only works for flags and exact value options");
 
 
  129        return BadNameString(
"Long names strings require 2 dashes " + name);
 
  136        return BadNameString(
"Names '-','--','++' are reserved and not allowed as option names " + name);
 
  138    static BadNameString MultiPositionalNames(std::string name) {
 
  139        return BadNameString(
"Only one positional name allowed, remove: " + name);
 
 
  149        return {name + 
" requires " + other, ExitCodes::OptionAlreadyAdded};
 
  152        return {name + 
" excludes " + other, ExitCodes::OptionAlreadyAdded};
 
 
  168    Success() : 
Success(
"Successfully completed, should be caught and quit", ExitCodes::Success) {}
 
 
  174    CallForHelp() : 
CallForHelp(
"This should be caught in your main function, see examples", ExitCodes::Success) {}
 
 
  181        : 
CallForAllHelp(
"This should be caught in your main function, see examples", ExitCodes::Success) {}
 
 
  188        : 
CallForVersion(
"This should be caught in your main function, see examples", ExitCodes::Success) {}
 
 
  201    static FileError Missing(std::string name) { 
return FileError(name + 
" was not readable (missing?)"); }
 
 
  209        : 
ConversionError(
"The value " + member + 
" is not an allowed value for " + name) {}
 
  211        : 
ConversionError(
"Could not convert: " + name + 
" = " + detail::join(results)) {}
 
 
  232        if(min_subcom == 1) {
 
  235        return {
"Requires at least " + std::to_string(min_subcom) + 
" subcommands", ExitCodes::RequiredError};
 
  238    Option(std::size_t min_option, std::size_t max_option, std::size_t used, 
const std::string &option_list) {
 
  239        if((min_option == 1) && (max_option == 1) && (used == 0))
 
  240            return RequiredError(
"Exactly 1 option from [" + option_list + 
"]");
 
  241        if((min_option == 1) && (max_option == 1) && (used > 1)) {
 
  242            return {
"Exactly 1 option from [" + option_list + 
"] is required but " + std::to_string(used) +
 
  244                    ExitCodes::RequiredError};
 
  246        if((min_option == 1) && (used == 0))
 
  247            return RequiredError(
"At least 1 option from [" + option_list + 
"]");
 
  248        if(used < min_option) {
 
  249            return {
"Requires at least " + std::to_string(min_option) + 
" options used but only " +
 
  250                        std::to_string(used) + 
" were given from [" + option_list + 
"]",
 
  251                    ExitCodes::RequiredError};
 
  254            return {
"Requires at most 1 options be given from [" + option_list + 
"]", ExitCodes::RequiredError};
 
  256        return {
"Requires at most " + std::to_string(max_option) + 
" options be used but " + std::to_string(used) +
 
  257                    " were given from [" + option_list + 
"]",
 
  258                ExitCodes::RequiredError};
 
 
  267        : 
ArgumentMismatch(expected > 0 ? (
"Expected exactly " + std::to_string(expected) + 
" arguments to " + name +
 
  268                                           ", got " + std::to_string(received))
 
  269                                        : (
"Expected at least " + std::to_string(-expected) + 
" arguments to " + name +
 
  270                                           ", got " + std::to_string(received)),
 
  271                           ExitCodes::ArgumentMismatch) {}
 
  273    static ArgumentMismatch AtLeast(std::string name, 
int num, std::size_t received) {
 
  274        return ArgumentMismatch(name + 
": At least " + std::to_string(num) + 
" required but received " +
 
  275                                std::to_string(received));
 
  277    static ArgumentMismatch AtMost(std::string name, 
int num, std::size_t received) {
 
  278        return ArgumentMismatch(name + 
": At most " + std::to_string(num) + 
" required but received " +
 
  279                                std::to_string(received));
 
  281    static ArgumentMismatch TypedAtLeast(std::string name, 
int num, std::string type) {
 
  282        return ArgumentMismatch(name + 
": " + std::to_string(num) + 
" required " + type + 
" missing");
 
  287    static ArgumentMismatch PartialType(std::string name, 
int num, std::string type) {
 
  288        return ArgumentMismatch(name + 
": " + type + 
" only partially specified: " + std::to_string(num) +
 
  289                                " required for each element");
 
 
  297        : 
RequiresError(curname + 
" requires " + subname, ExitCodes::RequiresError) {}
 
 
  304        : 
ExcludesError(curname + 
" excludes " + subname, ExitCodes::ExcludesError) {}
 
 
  310    explicit ExtrasError(std::vector<std::string> args)
 
  311        : 
ExtrasError((args.size() > 1 ? 
"The following arguments were not expected: " 
  312                                       : 
"The following argument was not expected: ") +
 
  313                          detail::join(args, 
" "),
 
  314                      ExitCodes::ExtrasError) {}
 
  315    ExtrasError(
const std::string &name, std::vector<std::string> args)
 
  317                      (args.size() > 1 ? 
"The following arguments were not expected: " 
  318                                       : 
"The following argument was not expected: ") +
 
  319                          detail::join(args, 
" "),
 
  320                      ExitCodes::ExtrasError) {}
 
 
  328    static ConfigError NotConfigurable(std::string item) {
 
  329        return ConfigError(item + 
": This option is not allowed in a configuration file");
 
 
  337        : 
InvalidError(name + 
": Too many positional arguments with unlimited expected args", ExitCodes::InvalidError) {
 
 
  356#undef CLI11_ERROR_DEF 
  357#undef CLI11_ERROR_SIMPLE 
Thrown when the wrong number of arguments has been received.
Definition Error.hpp:263
 
Thrown on construction of a bad name.
Definition Error.hpp:124
 
Usually something like –help-all on command line.
Definition Error.hpp:178
 
-h or –help on command line
Definition Error.hpp:172
 
-v or –version on command line
Definition Error.hpp:185
 
Thrown when extra values are found in an INI file.
Definition Error.hpp:324
 
Construction errors (not in parsing)
Definition Error.hpp:91
 
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition Error.hpp:205
 
All errors derive from this one.
Definition Error.hpp:73
 
Thrown when an excludes option is present.
Definition Error.hpp:301
 
Thrown when parsing an INI file and it is missing.
Definition Error.hpp:198
 
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition Error.hpp:96
 
Thrown when validation fails before parsing.
Definition Error.hpp:334
 
Thrown when an option already exists.
Definition Error.hpp:144
 
Definition Option.hpp:259
 
Thrown when counting a nonexistent option.
Definition Error.hpp:351
 
Anything that can error in Parse.
Definition Error.hpp:159
 
Thrown when a required option is missing.
Definition Error.hpp:228
 
Thrown when a requires option is missing.
Definition Error.hpp:294
 
Does not output a diagnostic in CLI11_PARSE, but allows main() to return with a specific error code.
Definition Error.hpp:192
 
This is a successful completion on parsing, supposed to exit.
Definition Error.hpp:166
 
Thrown when validation of results fails.
Definition Error.hpp:221