Commit d92988c6a218e2fef987e30d99445e7c87c4b87b
1 parent
db674a46
Allow for numbers in options
Closes #32. This adds numbers as allowed values in all parts of short and long option specifiers.
Showing
2 changed files
with
8 additions
and
4 deletions
src/cxxopts.hpp
| ... | ... | @@ -829,10 +829,10 @@ namespace cxxopts |
| 829 | 829 | constexpr int OPTION_DESC_GAP = 2; |
| 830 | 830 | |
| 831 | 831 | std::basic_regex<char> option_matcher |
| 832 | - ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([a-zA-Z]+)"); | |
| 832 | + ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)"); | |
| 833 | 833 | |
| 834 | 834 | std::basic_regex<char> option_specifier |
| 835 | - ("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)"); | |
| 835 | + ("(([[:alnum:]]),)?([[:alnum:]][-_[:alnum:]]+)"); | |
| 836 | 836 | |
| 837 | 837 | String |
| 838 | 838 | format_option | ... | ... |
test/options.cpp
| ... | ... | @@ -51,7 +51,9 @@ TEST_CASE("Basic options", "[options]") |
| 51 | 51 | ("long", "a long option") |
| 52 | 52 | ("s,short", "a short option") |
| 53 | 53 | ("value", "an option with a value", cxxopts::value<std::string>()) |
| 54 | - ("a,av", "a short option with a value", cxxopts::value<std::string>()); | |
| 54 | + ("a,av", "a short option with a value", cxxopts::value<std::string>()) | |
| 55 | + ("6,six", "a short number option") | |
| 56 | + ; | |
| 55 | 57 | |
| 56 | 58 | Argv argv({ |
| 57 | 59 | "tester", |
| ... | ... | @@ -60,7 +62,8 @@ TEST_CASE("Basic options", "[options]") |
| 60 | 62 | "--value", |
| 61 | 63 | "value", |
| 62 | 64 | "-a", |
| 63 | - "b" | |
| 65 | + "b", | |
| 66 | + "-6" | |
| 64 | 67 | }); |
| 65 | 68 | |
| 66 | 69 | char** actual_argv = argv.argv(); |
| ... | ... | @@ -74,6 +77,7 @@ TEST_CASE("Basic options", "[options]") |
| 74 | 77 | CHECK(options.count("a") == 1); |
| 75 | 78 | CHECK(options["value"].as<std::string>() == "value"); |
| 76 | 79 | CHECK(options["a"].as<std::string>() == "b"); |
| 80 | + CHECK(options.count("6") == 1); | |
| 77 | 81 | } |
| 78 | 82 | |
| 79 | 83 | TEST_CASE("No positional", "[positional]") | ... | ... |