Go to the documentation of this file.
18 #define CLI11_ERROR_DEF(parent, name) \
20 name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {} \
21 name(std::string ename, std::string msg, ExitCodes exit_code) \
22 : parent(std::move(ename), std::move(msg), exit_code) {} \
25 name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \
26 name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {}
29 #define CLI11_ERROR_SIMPLE(name) \
30 explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {}
63 class Error :
public std::runtime_error {
65 std::string error_name{
"Error"};
70 std::string
get_name()
const {
return error_name; }
73 : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {}
75 Error(std::string name, std::string msg,
ExitCodes exit_code) :
Error(name, msg, static_cast<int>(exit_code)) {}
103 name +
": You can't change expected arguments after you've changed the multi option policy!");
109 return IncorrectConstruction(name +
": multi_option_policy only works for flags and exact value options");
120 return BadNameString(
"Must have a name, not just dashes: " + name);
122 static BadNameString MultiPositionalNames(std::string name) {
123 return BadNameString(
"Only one positional name allowed, remove: " + name);
178 static FileError Missing(std::string name) {
return FileError(name +
" was not readable (missing?)"); }
186 :
ConversionError(
"The value " + member +
" is not an allowed value for " + name) {}
209 if(min_subcom == 1) {
216 Option(std::size_t min_option, std::size_t max_option, std::size_t used,
const std::string &option_list) {
217 if((min_option == 1) && (max_option == 1) && (used == 0))
218 return RequiredError(
"Exactly 1 option from [" + option_list +
"]");
219 if((min_option == 1) && (max_option == 1) && (used > 1)) {
224 if((min_option == 1) && (used == 0))
225 return RequiredError(
"At least 1 option from [" + option_list +
"]");
226 if(used < min_option) {
232 return RequiredError(
"Requires at most 1 options be given from [" + option_list +
"]",
248 : (
"Expected at least " +
std::to_string(-expected) +
" arguments to " + name +
252 static ArgumentMismatch AtLeast(std::string name,
int num, std::size_t received) {
256 static ArgumentMismatch AtMost(std::string name,
int num, std::size_t received) {
260 static ArgumentMismatch TypedAtLeast(std::string name,
int num, std::string type) {
285 explicit ExtrasError(std::vector<std::string> args)
286 :
ExtrasError((args.size() > 1 ?
"The following arguments were not expected: "
287 :
"The following argument was not expected: ") +
290 ExtrasError(
const std::string &name, std::vector<std::string> args)
292 (args.size() > 1 ?
"The following arguments were not expected: "
293 :
"The following argument was not expected: ") +
303 static ConfigError NotConfigurable(std::string item) {
304 return ConfigError(item +
": This option is not allowed in a configuration file");
331 #undef CLI11_ERROR_DEF
332 #undef CLI11_ERROR_SIMPLE
Thrown when parsing an INI file and it is missing.
Definition: Error.hpp:175
std::string rjoin(const T &v, std::string delim=",")
Join a string in reverse order.
Definition: StringTools.hpp:85
Thrown when an excludes option is present.
Definition: Error.hpp:276
This is a successful completion on parsing, supposed to exit.
Definition: Error.hpp:150
-h or –help on command line
Definition: Error.hpp:156
Anything that can error in Parse.
Definition: Error.hpp:143
Error(std::string name, std::string msg, ExitCodes exit_code)
Definition: Error.hpp:75
ExitCodes
Definition: Error.hpp:34
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition: Error.hpp:182
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:56
MultiOptionPolicy
Enumeration of the multiOption Policy selection.
Definition: Option.hpp:32
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
Definition: TypeTools.hpp:222
int get_exit_code() const
Definition: Error.hpp:68
Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error c...
Definition: Error.hpp:169
#define CLI11_ERROR_DEF(parent, name)
Definition: Error.hpp:18
std::string get_name() const
Definition: Error.hpp:70
Thrown on construction of a bad name.
Definition: Error.hpp:114
Construction errors (not in parsing)
Definition: Error.hpp:81
All errors derive from this one.
Definition: Error.hpp:63
Thrown when an option already exists.
Definition: Error.hpp:128
Definition: Option.hpp:228
Thrown when validation of results fails.
Definition: Error.hpp:198
Thrown when validation fails before parsing.
Definition: Error.hpp:309
Error(std::string name, std::string msg, int exit_code=static_cast< int >(ExitCodes::BaseClass))
Definition: Error.hpp:72
Usually something like –help-all on command line.
Definition: Error.hpp:162
Thrown when the wrong number of arguments has been received.
Definition: Error.hpp:242
Definition: Error.hpp:318
Thrown when a required option is missing.
Definition: Error.hpp:205
#define CLI11_ERROR_SIMPLE(name)
Definition: Error.hpp:29
Thrown when counting a non-existent option.
Definition: Error.hpp:326
Thrown when extra values are found in an INI file.
Definition: Error.hpp:299
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition: Error.hpp:86
Thrown when a requires option is missing.
Definition: Error.hpp:269