From f931fd4279e2638ac659fafe0b43fe71a031ecb2 Mon Sep 17 00:00:00 2001 From: Shivakar Vulli Date: Sun, 16 Jul 2017 15:11:03 +1000 Subject: [PATCH] Allow spaces in option specification. (#58) Fixes #57. Allows spaces after the comma between the short and long option specification. --- include/cxxopts.hpp | 2 +- src/example.cpp | 2 +- test/options.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index e08f46a..f4fa7df 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -884,7 +884,7 @@ namespace cxxopts ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)"); std::basic_regex option_specifier - ("(([[:alnum:]]),)?([[:alnum:]][-_[:alnum:]]*)?"); + ("(([[:alnum:]]),)?[ ]*([[:alnum:]][-_[:alnum:]]*)?"); String format_option diff --git a/src/example.cpp b/src/example.cpp index 85f0964..f9f50b2 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) options.add_options() ("a,apple", "an apple", cxxopts::value(apple)) ("b,bob", "Bob") - ("f,file", "File", cxxopts::value>(), "FILE") + ("f, file", "File", cxxopts::value>(), "FILE") ("i,input", "Input", cxxopts::value()) ("o,output", "Output file", cxxopts::value() ->default_value("a.out")->implicit_value("b.def"), "BIN") diff --git a/test/options.cpp b/test/options.cpp index 17354c9..62c21ed 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -52,6 +52,7 @@ TEST_CASE("Basic options", "[options]") ("value", "an option with a value", cxxopts::value()) ("a,av", "a short option with a value", cxxopts::value()) ("6,six", "a short number option") + ("p, space", "an option with space between short and long") ; Argv argv({ @@ -62,7 +63,9 @@ TEST_CASE("Basic options", "[options]") "value", "-a", "b", - "-6" + "-6", + "-p", + "--space", }); char** actual_argv = argv.argv(); @@ -77,6 +80,8 @@ TEST_CASE("Basic options", "[options]") CHECK(options["value"].as() == "value"); CHECK(options["a"].as() == "b"); CHECK(options.count("6") == 1); + CHECK(options.count("p") == 2); + CHECK(options.count("space") == 2); } TEST_CASE("Short options", "[options]")