File tree Expand file tree Collapse file tree 6 files changed +64
-23
lines changed Expand file tree Collapse file tree 6 files changed +64
-23
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,6 @@ public void Parse_diagram_identifies_options_where_default_values_have_been_appl
90
90
}
91
91
} ;
92
92
93
-
94
93
var result = rootCommand . Parse ( "-w 9000" ) ;
95
94
96
95
var diagram = result . Diagram ( ) ;
Original file line number Diff line number Diff line change @@ -1371,6 +1371,45 @@ public void When_an_option_with_a_default_value_is_not_matched_then_the_option_r
1371
1371
. BeTrue ( ) ;
1372
1372
}
1373
1373
1374
+ [ Fact ]
1375
+ public void When_an_option_with_a_default_value_is_not_matched_then_there_are_no_tokens ( )
1376
+ {
1377
+ var option = new Option < string > (
1378
+ "-o" ,
1379
+ ( ) => "the-default" ) ;
1380
+
1381
+ var command = new Command ( "command" )
1382
+ {
1383
+ option
1384
+ } ;
1385
+
1386
+ var result = command . Parse ( "command" ) ;
1387
+
1388
+ result . FindResultFor ( option )
1389
+ . Token
1390
+ . Should ( )
1391
+ . BeNull ( ) ;
1392
+ }
1393
+
1394
+ [ Fact ]
1395
+ public void When_an_argument_with_a_default_value_is_not_matched_then_there_are_no_tokens ( )
1396
+ {
1397
+ var argument = new Argument < string > (
1398
+ "o" ,
1399
+ ( ) => "the-default" ) ;
1400
+
1401
+ var command = new Command ( "command" )
1402
+ {
1403
+ argument
1404
+ } ;
1405
+ var result = command . Parse ( "command" ) ;
1406
+
1407
+ result . FindResultFor ( argument )
1408
+ . Tokens
1409
+ . Should ( )
1410
+ . BeEmpty ( ) ;
1411
+ }
1412
+
1374
1413
[ Fact ]
1375
1414
public void Command_default_argument_value_does_not_override_parsed_value ( )
1376
1415
{
Original file line number Diff line number Diff line change @@ -12,18 +12,18 @@ public class OptionResult : SymbolResult
12
12
13
13
internal OptionResult (
14
14
IOption option ,
15
- Token token ,
16
- CommandResult parent ) :
15
+ Token token = null ,
16
+ CommandResult parent = null ) :
17
17
base ( option ?? throw new ArgumentNullException ( nameof ( option ) ) ,
18
18
parent )
19
19
{
20
20
Option = option ;
21
- Token = token ?? throw new ArgumentNullException ( nameof ( token ) ) ;
21
+ Token = token ;
22
22
}
23
23
24
24
public IOption Option { get ; }
25
25
26
- public bool IsImplicit => Token is ImplicitToken ;
26
+ public bool IsImplicit => Token is ImplicitToken || Token is null ;
27
27
28
28
public Token Token { get ; }
29
29
Original file line number Diff line number Diff line change @@ -318,7 +318,7 @@ private void PopulateDefaultValues()
318
318
319
319
var optionResult = new OptionResult (
320
320
option ,
321
- option . CreateImplicitToken ( ) ,
321
+ null ,
322
322
commandResult ) ;
323
323
324
324
var childArgumentResult = optionResult . GetOrCreateDefaultArgumentResult (
Original file line number Diff line number Diff line change 2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections . Generic ;
5
+ using System . Linq ;
5
6
6
7
namespace System . CommandLine . Parsing
7
8
{
@@ -24,12 +25,24 @@ internal static IEnumerable<SymbolResult> AllSymbolResults(this SymbolResult sym
24
25
}
25
26
}
26
27
27
- internal static Token Token ( this SymbolResult symbolResult ) =>
28
- symbolResult switch
28
+ internal static Token Token ( this SymbolResult symbolResult )
29
+ {
30
+ return symbolResult switch
29
31
{
30
32
CommandResult commandResult => commandResult . Token ,
31
- OptionResult optionResult => optionResult . Token ,
33
+ OptionResult optionResult => optionResult . Token ??
34
+ CreateImplicitToken ( optionResult . Option ) ,
32
35
_ => throw new ArgumentOutOfRangeException ( nameof ( symbolResult ) )
33
36
} ;
37
+
38
+ Token CreateImplicitToken ( IOption option )
39
+ {
40
+ var optionName = option . Name ;
41
+
42
+ var defaultAlias = option . RawAliases . First ( alias => alias . RemovePrefix ( ) == optionName ) ;
43
+
44
+ return new ImplicitToken ( defaultAlias , TokenType . Option ) ;
45
+ }
46
+ }
34
47
}
35
- }
48
+ }
Original file line number Diff line number Diff line change 2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections . Generic ;
5
- using System . CommandLine . Parsing ;
6
5
using System . Linq ;
7
6
8
7
namespace System . CommandLine
@@ -11,8 +10,8 @@ internal static class SymbolExtensions
11
10
{
12
11
internal static IEnumerable < string > ChildSymbolAliases ( this ISymbol symbol ) =>
13
12
symbol . Children
14
- . Where ( s => ! s . IsHidden )
15
- . SelectMany ( s => s . RawAliases ) ;
13
+ . Where ( s => ! s . IsHidden )
14
+ . SelectMany ( s => s . RawAliases ) ;
16
15
17
16
internal static IEnumerable < IArgument > Arguments ( this ISymbol symbol )
18
17
{
@@ -34,14 +33,5 @@ internal static IEnumerable<IArgument> Arguments(this ISymbol symbol)
34
33
throw new NotSupportedException ( ) ;
35
34
}
36
35
}
37
-
38
- internal static Token CreateImplicitToken ( this IOption option )
39
- {
40
- var optionName = option . Name ;
41
-
42
- var defaultAlias = option . RawAliases . First ( alias => alias . RemovePrefix ( ) == optionName ) ;
43
-
44
- return new ImplicitToken ( defaultAlias , TokenType . Option ) ;
45
- }
46
36
}
47
- }
37
+ }
You can’t perform that action at this time.
0 commit comments