fix(command_line): Use specific exceptions
This commit is contained in:
parent
7efb2fc47a
commit
2921239833
@ -10,6 +10,8 @@
|
|||||||
LEMONBUDDY_NS
|
LEMONBUDDY_NS
|
||||||
|
|
||||||
namespace command_line {
|
namespace command_line {
|
||||||
|
DEFINE_ERROR(argument_error);
|
||||||
|
DEFINE_ERROR(value_error);
|
||||||
|
|
||||||
class option;
|
class option;
|
||||||
using choices = vector<string>;
|
using choices = vector<string>;
|
||||||
@ -171,18 +173,18 @@ namespace command_line {
|
|||||||
string value;
|
string value;
|
||||||
|
|
||||||
if (input_next.empty() && opt.compare(0, 2, "--") != 0)
|
if (input_next.empty() && opt.compare(0, 2, "--") != 0)
|
||||||
throw application_error("Missing value for " + opt);
|
throw value_error("Missing value for " + opt);
|
||||||
else if (!input_next.empty())
|
else if (!input_next.empty())
|
||||||
value = input_next;
|
value = input_next;
|
||||||
else if ((pos = opt.compare(0, 1, "=")) == string::npos)
|
else if ((pos = opt.find("=")) == string::npos)
|
||||||
throw application_error("Missing value for " + opt);
|
throw value_error("Missing value for " + opt);
|
||||||
else {
|
else {
|
||||||
value = opt.substr(pos + 1);
|
value = opt.substr(pos + 1);
|
||||||
opt = opt.substr(0, pos);
|
opt = opt.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!values.empty() && std::find(values.begin(), values.end(), value) == values.end())
|
if (!values.empty() && std::find(values.begin(), values.end(), value) == values.end())
|
||||||
throw application_error("Invalid argument '" + value + "' for " + string{opt});
|
throw value_error("Invalid value '" + value + "' for argument " + string{opt});
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -212,7 +214,7 @@ namespace command_line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input.compare(0, 1, "-") == 0) {
|
if (input.compare(0, 1, "-") == 0) {
|
||||||
throw application_error("Unrecognized option " + input);
|
throw argument_error("Unrecognized option " + input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user