Allow spaces in option specification. (#58)
Fixes #57. Allows spaces after the comma between the short and long option specification.
This commit is contained in:
parent
11faadeba7
commit
f931fd4279
@ -884,7 +884,7 @@ namespace cxxopts
|
|||||||
("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)");
|
("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)");
|
||||||
|
|
||||||
std::basic_regex<char> option_specifier
|
std::basic_regex<char> option_specifier
|
||||||
("(([[:alnum:]]),)?([[:alnum:]][-_[:alnum:]]*)?");
|
("(([[:alnum:]]),)?[ ]*([[:alnum:]][-_[:alnum:]]*)?");
|
||||||
|
|
||||||
String
|
String
|
||||||
format_option
|
format_option
|
||||||
|
|||||||
@ -38,7 +38,7 @@ int main(int argc, char* argv[])
|
|||||||
options.add_options()
|
options.add_options()
|
||||||
("a,apple", "an apple", cxxopts::value<bool>(apple))
|
("a,apple", "an apple", cxxopts::value<bool>(apple))
|
||||||
("b,bob", "Bob")
|
("b,bob", "Bob")
|
||||||
("f,file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
|
("f, file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
|
||||||
("i,input", "Input", cxxopts::value<std::string>())
|
("i,input", "Input", cxxopts::value<std::string>())
|
||||||
("o,output", "Output file", cxxopts::value<std::string>()
|
("o,output", "Output file", cxxopts::value<std::string>()
|
||||||
->default_value("a.out")->implicit_value("b.def"), "BIN")
|
->default_value("a.out")->implicit_value("b.def"), "BIN")
|
||||||
|
|||||||
@ -52,6 +52,7 @@ TEST_CASE("Basic options", "[options]")
|
|||||||
("value", "an option with a value", cxxopts::value<std::string>())
|
("value", "an option with a value", cxxopts::value<std::string>())
|
||||||
("a,av", "a short option with a value", cxxopts::value<std::string>())
|
("a,av", "a short option with a value", cxxopts::value<std::string>())
|
||||||
("6,six", "a short number option")
|
("6,six", "a short number option")
|
||||||
|
("p, space", "an option with space between short and long")
|
||||||
;
|
;
|
||||||
|
|
||||||
Argv argv({
|
Argv argv({
|
||||||
@ -62,7 +63,9 @@ TEST_CASE("Basic options", "[options]")
|
|||||||
"value",
|
"value",
|
||||||
"-a",
|
"-a",
|
||||||
"b",
|
"b",
|
||||||
"-6"
|
"-6",
|
||||||
|
"-p",
|
||||||
|
"--space",
|
||||||
});
|
});
|
||||||
|
|
||||||
char** actual_argv = argv.argv();
|
char** actual_argv = argv.argv();
|
||||||
@ -77,6 +80,8 @@ TEST_CASE("Basic options", "[options]")
|
|||||||
CHECK(options["value"].as<std::string>() == "value");
|
CHECK(options["value"].as<std::string>() == "value");
|
||||||
CHECK(options["a"].as<std::string>() == "b");
|
CHECK(options["a"].as<std::string>() == "b");
|
||||||
CHECK(options.count("6") == 1);
|
CHECK(options.count("6") == 1);
|
||||||
|
CHECK(options.count("p") == 2);
|
||||||
|
CHECK(options.count("space") == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Short options", "[options]")
|
TEST_CASE("Short options", "[options]")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user