@@ -77,8 +77,7 @@ void apply_syntax(options_description& desc,
77
77
v = value<string>();
78
78
s.resize (s.size ()-1 );
79
79
} else if (*(s.end ()-1 ) == ' ?' ) {
80
- // v = value<string>()->implicit();
81
- v = value<string>();
80
+ v = value<string>()->implicit_value (" default" );
82
81
s.resize (s.size ()-1 );
83
82
} else if (*(s.end ()-1 ) == ' *' ) {
84
83
v = value<vector<string> >()->multitoken ();
@@ -607,6 +606,34 @@ void test_unregistered()
607
606
// It's not clear yet, so I'm leaving the decision till later.
608
607
}
609
608
609
+ void test_implicit_value ()
610
+ {
611
+ using namespace command_line_style ;
612
+ cmdline::style_t style;
613
+
614
+ style = cmdline::style_t (
615
+ allow_long | long_allow_adjacent
616
+ );
617
+
618
+ test_case test_cases1[] = {
619
+ // 'bar' does not even look like option, so is consumed
620
+ {" --foo bar" , s_success, " foo:bar" },
621
+ // '--bar' looks like option, and such option exists, so we don't consume this token
622
+ {" --foo --bar" , s_success, " foo: bar:" },
623
+ // '--biz' looks like option, but does not match any existing one.
624
+ // Presently this results in parse error, since
625
+ // (1) in cmdline.cpp:finish_option, we only consume following tokens if they are
626
+ // requires
627
+ // (2) in cmdline.cpp:run, we let options consume following positional options
628
+ // For --biz, an exception is thrown between 1 and 2.
629
+ // We might want to fix that in future.
630
+ {" --foo --biz" , s_unknown_option, " " },
631
+ {0 , 0 , 0 }
632
+ };
633
+
634
+ test_cmdline (" foo? bar?" , style, test_cases1);
635
+ }
636
+
610
637
int main (int /* ac*/ , char ** /* av*/ )
611
638
{
612
639
test_long_options ();
@@ -619,6 +646,7 @@ int main(int /*ac*/, char** /*av*/)
619
646
test_additional_parser ();
620
647
test_style_parser ();
621
648
test_unregistered ();
649
+ test_implicit_value ();
622
650
623
651
return 0 ;
624
652
}
0 commit comments