Go to the documentation of this file.
22 #define CLI11_ERROR_DEF(parent, name) \
24 name(std::string ename, std::string msg, int exit_code) : parent(std::move(ename), std::move(msg), exit_code) {} \
25 name(std::string ename, std::string msg, ExitCodes exit_code) \
26 : parent(std::move(ename), std::move(msg), exit_code) {} \
29 name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \
30 name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {}
33 #define CLI11_ERROR_SIMPLE(name) \
34 explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {}
67 class Error :
public std::runtime_error {
69 std::string error_name{
"Error"};
74 std::string
get_name()
const {
return error_name; }
77 : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {}
79 Error(std::string name, std::string msg,
ExitCodes exit_code) :
Error(name, msg, static_cast<int>(exit_code)) {}
107 name +
": You can't change expected arguments after you've changed the multi option policy!");
113 return IncorrectConstruction(name +
": multi_option_policy only works for flags and exact value options");
124 return BadNameString(
"Must have a name, not just dashes: " + name);
126 static BadNameString MultiPositionalNames(std::string name) {
127 return BadNameString(
"Only one positional name allowed, remove: " + name);
182 static FileError Missing(std::string name) {
return FileError(name +
" was not readable (missing?)"); }
190 :
ConversionError(
"The value " + member +
" is not an allowed value for " + name) {}
213 if(min_subcom == 1) {
220 Option(std::size_t min_option, std::size_t max_option, std::size_t used,
const std::string &option_list) {
221 if((min_option == 1) && (max_option == 1) && (used == 0))
222 return RequiredError(
"Exactly 1 option from [" + option_list +
"]");
223 if((min_option == 1) && (max_option == 1) && (used > 1)) {
228 if((min_option == 1) && (used == 0))
229 return RequiredError(
"At least 1 option from [" + option_list +
"]");
230 if(used < min_option) {
236 return RequiredError(
"Requires at most 1 options be given from [" + option_list +
"]",
252 : (
"Expected at least " +
std::to_string(-expected) +
" arguments to " + name +
256 static ArgumentMismatch AtLeast(std::string name,
int num, std::size_t received) {
260 static ArgumentMismatch AtMost(std::string name,
int num, std::size_t received) {
264 static ArgumentMismatch TypedAtLeast(std::string name,
int num, std::string type) {
289 explicit ExtrasError(std::vector<std::string> args)
290 :
ExtrasError((args.size() > 1 ?
"The following arguments were not expected: "
291 :
"The following argument was not expected: ") +
294 ExtrasError(
const std::string &name, std::vector<std::string> args)
296 (args.size() > 1 ?
"The following arguments were not expected: "
297 :
"The following argument was not expected: ") +
307 static ConfigError NotConfigurable(std::string item) {
308 return ConfigError(item +
": This option is not allowed in a configuration file");
335 #undef CLI11_ERROR_DEF
336 #undef CLI11_ERROR_SIMPLE
Thrown when parsing an INI file and it is missing.
Definition: Error.hpp:179
std::string rjoin(const T &v, std::string delim=",")
Join a string in reverse order.
Definition: StringTools.hpp:88
Thrown when an excludes option is present.
Definition: Error.hpp:280
This is a successful completion on parsing, supposed to exit.
Definition: Error.hpp:154
-h or –help on command line
Definition: Error.hpp:160
Anything that can error in Parse.
Definition: Error.hpp:147
Error(std::string name, std::string msg, ExitCodes exit_code)
Definition: Error.hpp:79
ExitCodes
Definition: Error.hpp:38
Thrown when conversion call back fails, such as when an int fails to coerce to a string.
Definition: Error.hpp:186
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:59
MultiOptionPolicy
Enumeration of the multiOption Policy selection.
Definition: Option.hpp:35
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:226
int get_exit_code() const
Definition: Error.hpp:72
Does not output a diagnostic in CLI11_PARSE, but allows to return from main() with a specific error c...
Definition: Error.hpp:173
#define CLI11_ERROR_DEF(parent, name)
Definition: Error.hpp:22
std::string get_name() const
Definition: Error.hpp:74
Thrown on construction of a bad name.
Definition: Error.hpp:118
Construction errors (not in parsing)
Definition: Error.hpp:85
All errors derive from this one.
Definition: Error.hpp:67
Thrown when an option already exists.
Definition: Error.hpp:132
Definition: Option.hpp:231
Thrown when validation of results fails.
Definition: Error.hpp:202
Thrown when validation fails before parsing.
Definition: Error.hpp:313
Error(std::string name, std::string msg, int exit_code=static_cast< int >(ExitCodes::BaseClass))
Definition: Error.hpp:76
Usually something like –help-all on command line.
Definition: Error.hpp:166
Thrown when the wrong number of arguments has been received.
Definition: Error.hpp:246
Definition: Error.hpp:322
Thrown when a required option is missing.
Definition: Error.hpp:209
#define CLI11_ERROR_SIMPLE(name)
Definition: Error.hpp:33
Thrown when counting a non-existent option.
Definition: Error.hpp:330
Thrown when extra values are found in an INI file.
Definition: Error.hpp:303
Thrown when an option is set to conflicting values (non-vector and multi args, for example)
Definition: Error.hpp:90
Thrown when a requires option is missing.
Definition: Error.hpp:273