Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jarro2783/cxxopts.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjarro2783 <jarro.2783@gmail.com>2022-08-13 00:51:41 +0300
committerGitHub <noreply@github.com>2022-08-13 00:51:41 +0300
commita10bd5233b9607ad236ee24a46475a65ec9e98c7 (patch)
treec1d229eb978fd0629cd1b77039a76b7d3191d091
parent17b2c91049fe8d74f763d3d5c3bea756f0097f5a (diff)
Fix values attached to short options (#360)
Fixes #357.
-rw-r--r--include/cxxopts.hpp2
-rw-r--r--test/options.cpp19
2 files changed, 14 insertions, 7 deletions
diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp
index d9ecca8..2895890 100644
--- a/include/cxxopts.hpp
+++ b/include/cxxopts.hpp
@@ -754,7 +754,7 @@ std::basic_regex<char> falsy_pattern
("(f|F)(alse)?|0");
std::basic_regex<char> option_matcher
- ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)");
+ ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]].*)");
std::basic_regex<char> option_specifier
("([[:alnum:]][-_[:alnum:]]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
std::basic_regex<char> option_specifier_separator(", *");
diff --git a/test/options.cpp b/test/options.cpp
index df6a2e7..6da106e 100644
--- a/test/options.cpp
+++ b/test/options.cpp
@@ -118,9 +118,11 @@ TEST_CASE("Short options", "[options]")
cxxopts::Options options("test_short", " - test short options");
options.add_options()
- ("a", "a short option", cxxopts::value<std::string>());
+ ("a", "a short option", cxxopts::value<std::string>())
+ ("b", "b option")
+ ("c", "c option", cxxopts::value<std::string>());
- Argv argv({"test_short", "-a", "value"});
+ Argv argv({"test_short", "-a", "value", "-bcfoo=something"});
auto actual_argv = argv.argv();
auto argc = argv.argc();
@@ -131,10 +133,15 @@ TEST_CASE("Short options", "[options]")
CHECK(result["a"].as<std::string>() == "value");
auto& arguments = result.arguments();
- REQUIRE(arguments.size() == 1);
+ REQUIRE(arguments.size() == 3);
CHECK(arguments[0].key() == "a");
CHECK(arguments[0].value() == "value");
+ CHECK(result.count("b") == 1);
+ CHECK(result.count("c") == 1);
+
+ CHECK(result["c"].as<std::string>() == "foo=something");
+
REQUIRE_THROWS_AS(options.add_options()("", "nothing option"),
cxxopts::exceptions::invalid_option_format&);
}
@@ -703,8 +710,8 @@ TEST_CASE("Allow bad short syntax", "[options]") {
("s,short", "a short option");
Argv av({
- "unknown_options",
- "-some_bad_short",
+ "--ab?",
+ "-?b?#@"
});
auto** argv = av.argv();
@@ -718,7 +725,7 @@ TEST_CASE("Allow bad short syntax", "[options]") {
options.allow_unrecognised_options();
CHECK_NOTHROW(options.parse(argc, argv));
REQUIRE(argc == 2);
- CHECK_THAT(argv[1], Catch::Equals("-some_bad_short"));
+ CHECK_THAT(argv[1], Catch::Equals("-?b?#@"));
}
}