Support options like -j5. (#286)
* Support option value being attached after the option without a space in between. e.g. -j5
This commit is contained in:
parent
056a6281ac
commit
97a4d5511f
@ -2295,6 +2295,12 @@ OptionParser::parse(int argc, const char* const* argv)
|
|||||||
{
|
{
|
||||||
parse_option(value, name, value->value().get_implicit_value());
|
parse_option(value, name, value->value().get_implicit_value());
|
||||||
}
|
}
|
||||||
|
else if (i + 1 < s.size())
|
||||||
|
{
|
||||||
|
std::string arg_value = s.substr(i + 1);
|
||||||
|
parse_option(value, name, arg_value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//error
|
//error
|
||||||
|
|||||||
@ -779,3 +779,28 @@ TEST_CASE("Const array", "[const]") {
|
|||||||
cxxopts::Options options("Empty options", " - test constness");
|
cxxopts::Options options("Empty options", " - test constness");
|
||||||
auto result = options.parse(2, option_list);
|
auto result = options.parse(2, option_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Parameter follow option", "[parameter]") {
|
||||||
|
cxxopts::Options options("param_follow_opt", " - test parameter follow option without space.");
|
||||||
|
options.add_options()
|
||||||
|
("j,job", "Job", cxxopts::value<std::vector<unsigned>>());
|
||||||
|
Argv av({"implicit",
|
||||||
|
"-j", "9",
|
||||||
|
"--job", "7",
|
||||||
|
"--job=10",
|
||||||
|
"-j5",
|
||||||
|
});
|
||||||
|
|
||||||
|
auto ** argv = av.argv();
|
||||||
|
auto argc = av.argc();
|
||||||
|
|
||||||
|
auto result = options.parse(argc, argv);
|
||||||
|
|
||||||
|
REQUIRE(result.count("job") == 4);
|
||||||
|
|
||||||
|
auto job_values = result["job"].as<std::vector<unsigned>>();
|
||||||
|
CHECK(job_values[0] == 9);
|
||||||
|
CHECK(job_values[1] == 7);
|
||||||
|
CHECK(job_values[2] == 10);
|
||||||
|
CHECK(job_values[3] == 5);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user