From d92988c6a218e2fef987e30d99445e7c87c4b87b Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Wed, 16 Nov 2016 18:03:35 +1100 Subject: [PATCH] Allow for numbers in options --- src/cxxopts.hpp | 4 ++-- test/options.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index d7b0f68..8c92613 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -829,10 +829,10 @@ namespace cxxopts constexpr int OPTION_DESC_GAP = 2; std::basic_regex option_matcher - ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([a-zA-Z]+)"); + ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)"); std::basic_regex option_specifier - ("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)"); + ("(([[:alnum:]]),)?([[:alnum:]][-_[:alnum:]]+)"); String format_option diff --git a/test/options.cpp b/test/options.cpp index 5e6b5c1..c15f6a3 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -51,7 +51,9 @@ TEST_CASE("Basic options", "[options]") ("long", "a long option") ("s,short", "a short option") ("value", "an option with a value", cxxopts::value()) - ("a,av", "a short option with a value", cxxopts::value()); + ("a,av", "a short option with a value", cxxopts::value()) + ("6,six", "a short number option") + ; Argv argv({ "tester", @@ -60,7 +62,8 @@ TEST_CASE("Basic options", "[options]") "--value", "value", "-a", - "b" + "b", + "-6" }); char** actual_argv = argv.argv(); @@ -74,6 +77,7 @@ TEST_CASE("Basic options", "[options]") CHECK(options.count("a") == 1); CHECK(options["value"].as() == "value"); CHECK(options["a"].as() == "b"); + CHECK(options.count("6") == 1); } TEST_CASE("No positional", "[positional]") -- libgit2 0.21.4