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:
RonxBulld
2021-05-06 08:46:40 +10:00
committed by GitHub
parent 056a6281ac
commit 97a4d5511f
2 changed files with 31 additions and 0 deletions
+25
View File
@@ -779,3 +779,28 @@ TEST_CASE("Const array", "[const]") {
cxxopts::Options options("Empty options", " - test constness");
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);
}