Commit f931fd4279e2638ac659fafe0b43fe71a031ecb2

Authored by Shivakar Vulli
Committed by Jarryd Beck
1 parent 11faadeb

Allow spaces in option specification. (#58)

Fixes #57.

Allows spaces after the comma between the short and long option
specification.
include/cxxopts.hpp
... ... @@ -884,7 +884,7 @@ namespace cxxopts
884 884 ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]]+)");
885 885  
886 886 std::basic_regex<char> option_specifier
887   - ("(([[:alnum:]]),)?([[:alnum:]][-_[:alnum:]]*)?");
  887 + ("(([[:alnum:]]),)?[ ]*([[:alnum:]][-_[:alnum:]]*)?");
888 888  
889 889 String
890 890 format_option
... ...
src/example.cpp
... ... @@ -38,7 +38,7 @@ int main(int argc, char* argv[])
38 38 options.add_options()
39 39 ("a,apple", "an apple", cxxopts::value<bool>(apple))
40 40 ("b,bob", "Bob")
41   - ("f,file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
  41 + ("f, file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
42 42 ("i,input", "Input", cxxopts::value<std::string>())
43 43 ("o,output", "Output file", cxxopts::value<std::string>()
44 44 ->default_value("a.out")->implicit_value("b.def"), "BIN")
... ...
test/options.cpp
... ... @@ -52,6 +52,7 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
52 52 ("value", "an option with a value", cxxopts::value<std::string>())
53 53 ("a,av", "a short option with a value", cxxopts::value<std::string>())
54 54 ("6,six", "a short number option")
  55 + ("p, space", "an option with space between short and long")
55 56 ;
56 57  
57 58 Argv argv({
... ... @@ -62,7 +63,9 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
62 63 "value",
63 64 "-a",
64 65 "b",
65   - "-6"
  66 + "-6",
  67 + "-p",
  68 + "--space",
66 69 });
67 70  
68 71 char** actual_argv = argv.argv();
... ... @@ -77,6 +80,8 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
77 80 CHECK(options["value"].as<std::string>() == "value");
78 81 CHECK(options["a"].as<std::string>() == "b");
79 82 CHECK(options.count("6") == 1);
  83 + CHECK(options.count("p") == 2);
  84 + CHECK(options.count("space") == 2);
80 85 }
81 86  
82 87 TEST_CASE("Short options", "[options]")
... ...