File tree Expand file tree Collapse file tree 3 files changed +39
-6
lines changed
System.CommandLine/Parsing Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,31 @@ public void Multiple_arguments_of_unspecified_type_are_parsed_correctly()
144144 . Be ( "dest.txt" ) ;
145145 }
146146
147+
148+ [ Fact ]
149+ public void When_multiple_arguments_are_defined_but_not_provided_then_option_parses_correctly ( )
150+ {
151+ var option = new Option < string > ( "-e" ) ;
152+ var command = new Command ( "the-command" ) { option } ;
153+
154+ command . AddArgument ( new Argument < string >
155+ {
156+ Name = "arg1" ,
157+ } ) ;
158+
159+ command . AddArgument ( new Argument < string >
160+ {
161+ Name = "arg2" ,
162+ } ) ;
163+
164+ var result = command . Parse ( "-e foo" ) ;
165+
166+ var optionResult = result . ValueForOption ( option ) ;
167+
168+ optionResult . Should ( ) . Be ( "foo" ) ;
169+ }
170+
171+
147172 [ Fact ]
148173 public void tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_next_multiple_arity_argument ( )
149174 {
Original file line number Diff line number Diff line change @@ -48,12 +48,17 @@ internal ArgumentConversionResult ArgumentConversionResult
4848 {
4949 if ( _argumentConversionResult is null )
5050 {
51- var results = Children
52- . OfType < ArgumentResult > ( )
53- . Select ( r => r . GetArgumentConversionResult ( ) ) ;
51+ for ( var i = 0 ; i < Children . Count ; i ++ )
52+ {
53+ var child = Children [ i ] ;
5454
55- _argumentConversionResult = results . SingleOrDefault ( ) ??
56- ArgumentConversionResult . None ( Option . Argument ) ;
55+ if ( child is ArgumentResult argumentResult )
56+ {
57+ return _argumentConversionResult = argumentResult . GetArgumentConversionResult ( ) ;
58+ }
59+ }
60+
61+ return _argumentConversionResult = ArgumentConversionResult . None ( Option . Argument ) ;
5762 }
5863
5964 return _argumentConversionResult ;
Original file line number Diff line number Diff line change @@ -199,7 +199,10 @@ protected override void Stop(SyntaxNode node)
199199
200200 argumentResults . Add ( nextArgumentResult ) ;
201201
202- previousArgumentResult . Parent ! . Children . Add ( nextArgumentResult ) ;
202+ if ( previousArgumentResult . Parent is CommandResult commandResult )
203+ {
204+ commandResult . Children . Add ( nextArgumentResult ) ;
205+ }
203206
204207 _rootCommandResult . AddToSymbolMap ( nextArgumentResult ) ;
205208 }
You can’t perform that action at this time.
0 commit comments