Skip to content

Commit 35c8e12

Browse files
authored
remove obsolete SymbolResult.Arguments (#725)
1 parent 80a8e10 commit 35c8e12

File tree

7 files changed

+90
-60
lines changed

7 files changed

+90
-60
lines changed

src/System.CommandLine.Tests/Binding/TypeConversionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public void Custom_types_and_conversion_logic_can_be_specified()
2121
var argument = new Argument<MyCustomType>((SymbolResult parsed, out MyCustomType value) =>
2222
{
2323
var custom = new MyCustomType();
24-
foreach (var a in parsed.Arguments)
24+
foreach (var a in parsed.Tokens)
2525
{
26-
custom.Add(a);
26+
custom.Add(a.Value);
2727
}
2828

2929
value = custom;
@@ -263,7 +263,7 @@ public void When_argument_cannot_be_parsed_as_the_specified_type_then_getting_va
263263
{
264264
Argument = new Argument<int>((SymbolResult symbol, out int value) =>
265265
{
266-
if (int.TryParse(symbol.Arguments.Single(), out value))
266+
if (int.TryParse(symbol.Tokens.Select(t => t.Value).Single(), out value))
267267
{
268268
return true;
269269
}
@@ -708,7 +708,7 @@ public void When_custom_conversion_fails_then_an_option_does_not_accept_further_
708708

709709
var result = command.Parse("the-command -x nope yep");
710710

711-
result.CommandResult.Arguments.Count.Should().Be(1);
711+
result.CommandResult.Tokens.Count.Should().Be(1);
712712
}
713713

714714
[Fact]

src/System.CommandLine.Tests/CommandTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public void Inner_command_option_argument_is_identified_correctly()
9191
result.CommandResult
9292
.Children
9393
.ElementAt(0)
94-
.Arguments
94+
.Tokens
95+
.Select(t => t.Value)
9596
.Should()
9697
.BeEquivalentTo("argument1");
9798
}
@@ -121,12 +122,14 @@ public void Commands_at_multiple_levels_can_have_their_own_arguments()
121122

122123
result.CommandResult
123124
.Parent
124-
.Arguments
125+
.Tokens
126+
.Select(t => t.Value)
125127
.Should()
126128
.BeEquivalentTo("arg1");
127129

128130
result.CommandResult
129-
.Arguments
131+
.Tokens
132+
.Select(t => t.Value)
130133
.Should()
131134
.BeEquivalentTo("arg2", "arg3");
132135
}

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public void Parse_result_contains_arguments_to_options()
130130

131131
var result = parser.Parse("-o args_for_one -t args_for_two");
132132

133-
result["one"].Arguments.Single().Should().Be("args_for_one");
134-
result["two"].Arguments.Single().Should().Be("args_for_two");
133+
result["one"].Tokens.Single().Value.Should().Be("args_for_one");
134+
result["two"].Tokens.Single().Value.Should().Be("args_for_two");
135135
}
136136

137137
[Fact]
@@ -208,7 +208,7 @@ public void Short_form_options_can_be_specified_using_equals_delimiter()
208208

209209
result.Errors.Should().BeEmpty();
210210

211-
result["x"].Arguments.Should().ContainSingle(a => a == "some-value");
211+
result["x"].Tokens.Should().ContainSingle(a => a.Value == "some-value");
212212
}
213213

214214
[Fact]
@@ -227,7 +227,7 @@ public void Long_form_options_can_be_specified_using_equals_delimiter()
227227

228228
result.Errors.Should().BeEmpty();
229229

230-
result["hello"].Arguments.Should().ContainSingle(a => a == "there");
230+
result["hello"].Tokens.Should().ContainSingle(a => a.Value == "there");
231231
}
232232

233233
[Fact]
@@ -246,7 +246,7 @@ public void Short_form_options_can_be_specified_using_colon_delimiter()
246246

247247
result.Errors.Should().BeEmpty();
248248

249-
result["x"].Arguments.Should().ContainSingle(a => a == "some-value");
249+
result["x"].Tokens.Should().ContainSingle(a => a.Value == "some-value");
250250
}
251251

252252
[Fact]
@@ -264,7 +264,7 @@ public void Long_form_options_can_be_specified_using_colon_delimiter()
264264

265265
result.Errors.Should().BeEmpty();
266266

267-
result["hello"].Arguments.Should().ContainSingle(a => a == "there");
267+
result["hello"].Tokens.Should().ContainSingle(a => a.Value == "there");
268268
}
269269

270270
[Fact]
@@ -346,7 +346,8 @@ public void Options_do_not_get_unbundled_unless_all_resulting_options_would_be_v
346346
ParseResult result = parser.Parse("outer inner -abc");
347347

348348
result.CommandResult
349-
.Arguments
349+
.Tokens
350+
.Select(t => t.Value)
350351
.Should()
351352
.BeEquivalentTo("-abc");
352353
}
@@ -574,12 +575,14 @@ public void Parser_root_Options_can_be_specified_multiple_times_and_their_argume
574575
var result = parser.Parse("-a cat -v carrot -a dog");
575576

576577
result["animals"]
577-
.Arguments
578+
.Tokens
579+
.Select(t => t.Value)
578580
.Should()
579581
.BeEquivalentTo("cat", "dog");
580582

581583
result["vegetables"]
582-
.Arguments
584+
.Tokens
585+
.Select(t => t.Value)
583586
.Should()
584587
.BeEquivalentTo("carrot");
585588
}
@@ -610,12 +613,14 @@ public void Options_can_be_specified_multiple_times_and_their_arguments_are_coll
610613
var command = result.CommandResult;
611614

612615
command["animals"]
613-
.Arguments
616+
.Tokens
617+
.Select(t => t.Value)
614618
.Should()
615619
.BeEquivalentTo("cat", "dog");
616620

617621
command["vegetables"]
618-
.Arguments
622+
.Tokens
623+
.Select(t => t.Value)
619624
.Should()
620625
.BeEquivalentTo("carrot");
621626
}
@@ -642,12 +647,14 @@ public void When_a_Parser_root_option_is_not_respecified_but_limit_is_not_reache
642647
ParseResult result = parser.Parse("-a cat dog -v carrot");
643648

644649
result["animals"]
645-
.Arguments
650+
.Tokens
651+
.Select(t => t.Value)
646652
.Should()
647653
.BeEquivalentTo(new[] { "cat", "dog" });
648654

649655
result["vegetables"]
650-
.Arguments
656+
.Tokens
657+
.Select(t => t.Value)
651658
.Should()
652659
.BeEquivalentTo("carrot");
653660

@@ -679,12 +686,14 @@ public void When_a_Parser_root_option_is_not_respecified_and_limit_is_reached_th
679686
ParseResult result = parser.Parse("-a cat some-arg -v carrot");
680687

681688
result["animals"]
682-
.Arguments
689+
.Tokens
690+
.Select(t => t.Value)
683691
.Should()
684692
.BeEquivalentTo("cat");
685693

686694
result["vegetables"]
687-
.Arguments
695+
.Tokens
696+
.Select(t => t.Value)
688697
.Should()
689698
.BeEquivalentTo("carrot");
690699

@@ -725,17 +734,19 @@ public void When_an_option_is_not_respecified_but_limit_is_not_reached_then_the_
725734
var command = result.CommandResult;
726735

727736
command["animals"]
728-
.Arguments
737+
.Tokens
738+
.Select(t => t.Value)
729739
.Should()
730740
.BeEquivalentTo("cat", "dog");
731741

732742
command["vegetables"]
733-
.Arguments
743+
.Tokens
744+
.Select(t => t.Value)
734745
.Should()
735746
.BeEquivalentTo("carrot");
736747

737748
command
738-
.Arguments
749+
.Tokens
739750
.Should()
740751
.BeNullOrEmpty();
741752
}
@@ -770,17 +781,20 @@ public void When_an_option_is_not_respecified_but_limit_is_reached_then_the_foll
770781
var command = result.CommandResult;
771782

772783
command["animals"]
773-
.Arguments
784+
.Tokens
785+
.Select(t => t.Value)
774786
.Should()
775787
.BeEquivalentTo("cat");
776788

777789
command["vegetables"]
778-
.Arguments
790+
.Tokens
791+
.Select(t => t.Value)
779792
.Should()
780793
.BeEquivalentTo("carrot");
781794

782795
command
783-
.Arguments
796+
.Tokens
797+
.Select(t => t.Value)
784798
.Should()
785799
.BeEquivalentTo("some-arg");
786800
}
@@ -815,13 +829,13 @@ public void Command_with_multiple_options_is_parsed_correctly()
815829
.Should()
816830
.ContainSingle(o =>
817831
o.Symbol.Name == "inner1" &&
818-
o.Arguments.Single() == "argument1");
832+
o.Tokens.Single().Value == "argument1");
819833
result.CommandResult
820834
.Children
821835
.Should()
822836
.ContainSingle(o =>
823837
o.Symbol.Name == "inner2" &&
824-
o.Arguments.Single() == "argument2");
838+
o.Tokens.Single().Value == "argument2");
825839
}
826840

827841
[Fact]
@@ -946,9 +960,17 @@ public void When_nested_commands_all_accept_arguments_then_the_nearest_captures_
946960

947961
var result = command.Parse("outer arg1 inner arg2");
948962

949-
result.CommandResult.Parent.Arguments.Should().BeEquivalentTo("arg1");
963+
result.CommandResult
964+
.Parent
965+
.Tokens.Select(t => t.Value)
966+
.Should()
967+
.BeEquivalentTo("arg1");
950968

951-
result.CommandResult.Arguments.Should().BeEquivalentTo("arg2");
969+
result.CommandResult
970+
.Tokens
971+
.Select(t => t.Value)
972+
.Should()
973+
.BeEquivalentTo("arg2");
952974
}
953975

954976
[Fact]
@@ -989,8 +1011,8 @@ public void When_child_option_will_not_accept_arg_then_parent_can()
9891011

9901012
_output.WriteLine(result.ToString());
9911013

992-
result.CommandResult["x"].Arguments.Should().BeEmpty();
993-
result.CommandResult.Arguments.Should().BeEquivalentTo("the-argument");
1014+
result.CommandResult["x"].Tokens.Should().BeEmpty();
1015+
result.CommandResult.Tokens.Select(t => t.Value).Should().BeEquivalentTo("the-argument");
9941016
}
9951017

9961018
[Fact]
@@ -1006,10 +1028,10 @@ public void When_parent_option_will_not_accept_arg_then_child_can()
10061028

10071029
var result = command.Parse("the-command -x the-argument");
10081030

1009-
result.CommandResult["x"].Arguments.Should().BeEquivalentTo("the-argument");
1010-
result.CommandResult.Arguments.Should().BeEmpty();
1031+
result.CommandResult["x"].Tokens.Select(t => t.Value).Should().BeEquivalentTo("the-argument");
1032+
result.CommandResult.Tokens.Should().BeEmpty();
10111033
}
1012-
1034+
10131035
[Fact]
10141036
public void Required_arguments_on_parent_commands_do_not_create_parse_errors_when_an_inner_command_is_specified()
10151037
{
@@ -1110,11 +1132,12 @@ public void Arguments_only_apply_to_the_nearest_command()
11101132

11111133
result.CommandResult
11121134
.Parent
1113-
.Arguments
1135+
.Tokens
11141136
.Should()
11151137
.BeEmpty();
11161138
result.CommandResult
1117-
.Arguments
1139+
.Tokens
1140+
.Select(t => t.Value)
11181141
.Should()
11191142
.BeEquivalentTo("arg1");
11201143
result.UnmatchedTokens
@@ -1173,7 +1196,7 @@ public void Subsequent_occurrences_of_tokens_matching_command_names_are_parsed_a
11731196

11741197
CommandResult completeResult = result.CommandResult;
11751198

1176-
completeResult.Arguments.Should().BeEquivalentTo("the-command");
1199+
completeResult.Tokens.Select(t => t.Value).Should().BeEquivalentTo("the-command");
11771200
}
11781201

11791202
[Fact]
@@ -1266,7 +1289,8 @@ public void Absolute_unix_style_paths_are_lexed_correctly()
12661289
var result = parser.Parse(command);
12671290

12681291
result.CommandResult
1269-
.Arguments
1292+
.Tokens
1293+
.Select(t => t.Value)
12701294
.Should()
12711295
.OnlyContain(a => a == @"/temp/the file.txt");
12721296
}
@@ -1288,9 +1312,9 @@ public void Absolute_Windows_style_paths_are_lexed_correctly()
12881312
ParseResult result = parser.Parse(command);
12891313

12901314
result.CommandResult
1291-
.Arguments
1315+
.Tokens
12921316
.Should()
1293-
.OnlyContain(a => a == @"c:\temp\the file.txt\");
1317+
.OnlyContain(a => a.Value == @"c:\temp\the file.txt\");
12941318
}
12951319

12961320
[Fact]
@@ -1388,7 +1412,8 @@ public void Unmatched_options_are_not_split_into_smaller_tokens()
13881412
ParseResult result = outer.Parse("outer inner -p:RandomThing=random");
13891413

13901414
result.CommandResult
1391-
.Arguments
1415+
.Tokens
1416+
.Select(t => t.Value)
13921417
.Should()
13931418
.BeEquivalentTo("-p:RandomThing=random");
13941419
}
@@ -1440,7 +1465,8 @@ public void Argument_names_can_collide_with_option_names()
14401465
ParseResult result = command.Parse("the-command --one one");
14411466

14421467
result.CommandResult["one"]
1443-
.Arguments
1468+
.Tokens
1469+
.Select(t => t.Value)
14441470
.Should()
14451471
.BeEquivalentTo("one");
14461472
}
@@ -1531,7 +1557,8 @@ public void When_an_argument_is_enclosed_in_double_quotes_its_value_has_the_quot
15311557
})
15321558
.Parse(input);
15331559

1534-
parseResult["x"].Arguments
1560+
parseResult["x"].Tokens
1561+
.Select(t => t.Value)
15351562
.Should()
15361563
.BeEquivalentTo(new[] { expected });
15371564
}

0 commit comments

Comments
 (0)