Commit 2e3c6991d33811878ebcc0839d3815850d129b3a

Authored by Ryan Leary
Committed by GitHub
1 parent 2123115f

add . as valid char in option names (#358)

include/cxxopts.hpp
@@ -678,7 +678,8 @@ inline OptionNames split_option_names(const std::string &text) @@ -678,7 +678,8 @@ inline OptionNames split_option_names(const std::string &text)
678 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 678 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
679 "abcdefghijklmnopqrstuvwxyz" 679 "abcdefghijklmnopqrstuvwxyz"
680 "0123456789" 680 "0123456789"
681 - "_-"; 681 + "_-.?";
  682 +
682 if (!std::isalnum(text[token_start_pos], std::locale::classic()) || 683 if (!std::isalnum(text[token_start_pos], std::locale::classic()) ||
683 text.find_first_not_of(option_name_valid_chars, token_start_pos) < next_delimiter_pos) { 684 text.find_first_not_of(option_name_valid_chars, token_start_pos) < next_delimiter_pos) {
684 throw_or_mimic<exceptions::invalid_option_format>(text); 685 throw_or_mimic<exceptions::invalid_option_format>(text);
@@ -752,9 +753,9 @@ std::basic_regex&lt;char&gt; falsy_pattern @@ -752,9 +753,9 @@ std::basic_regex&lt;char&gt; falsy_pattern
752 ("(f|F)(alse)?|0"); 753 ("(f|F)(alse)?|0");
753 754
754 std::basic_regex<char> option_matcher 755 std::basic_regex<char> option_matcher
755 - ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]].*)"); 756 + ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)");
756 std::basic_regex<char> option_specifier 757 std::basic_regex<char> option_specifier
757 - ("([[:alnum:]][-_[:alnum:]]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*"); 758 + ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
758 std::basic_regex<char> option_specifier_separator(", *"); 759 std::basic_regex<char> option_specifier_separator(", *");
759 760
760 } // namespace 761 } // namespace
test/options.cpp
@@ -56,6 +56,7 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;) @@ -56,6 +56,7 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
56 ("a,av", "a short option with a value", cxxopts::value<std::string>()) 56 ("a,av", "a short option with a value", cxxopts::value<std::string>())
57 ("6,six", "a short number option") 57 ("6,six", "a short number option")
58 ("p, space", "an option with space between short and long") 58 ("p, space", "an option with space between short and long")
  59 + ("period.delimited", "an option with a period in the long name")
59 ("nothing", "won't exist", cxxopts::value<std::string>()) 60 ("nothing", "won't exist", cxxopts::value<std::string>())
60 ; 61 ;
61 62
@@ -77,7 +78,8 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;) @@ -77,7 +78,8 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
77 "-z", 78 "-z",
78 "--over", 79 "--over",
79 "--dog", 80 "--dog",
80 - "--lazy" 81 + "--lazy",
  82 + "--period.delimited",
81 }); 83 });
82 84
83 auto** actual_argv = argv.argv(); 85 auto** actual_argv = argv.argv();
@@ -97,9 +99,10 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;) @@ -97,9 +99,10 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
97 CHECK(result.count("quick") == 2); 99 CHECK(result.count("quick") == 2);
98 CHECK(result.count("f") == 2); 100 CHECK(result.count("f") == 2);
99 CHECK(result.count("z") == 4); 101 CHECK(result.count("z") == 4);
  102 + CHECK(result.count("period.delimited") == 1);
100 103
101 auto& arguments = result.arguments(); 104 auto& arguments = result.arguments();
102 - REQUIRE(arguments.size() == 15); 105 + REQUIRE(arguments.size() == 16);
103 CHECK(arguments[0].key() == "long"); 106 CHECK(arguments[0].key() == "long");
104 CHECK(arguments[0].value() == "true"); 107 CHECK(arguments[0].value() == "true");
105 CHECK(arguments[0].as<bool>() == true); 108 CHECK(arguments[0].as<bool>() == true);