Skip to content

Commit 08c6d9b

Browse files
authored
reorganize extension methods (#742)
* clean up invocation extensions, move Command.Invoke* to System.CommandLine namespace * move methods from InvocationExtensions into other namespaces * fix E2E test
1 parent 43c57ad commit 08c6d9b

File tree

17 files changed

+501
-508
lines changed

17 files changed

+501
-508
lines changed

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_TypoCorrection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public IEnumerable<BdnParam<ParseResult>> GenerateTestParseResults()
5757
[Benchmark]
5858
[ArgumentsSource(nameof(GenerateTestParseResults))]
5959
public async Task TypoCorrection(BdnParam<ParseResult> parseResult)
60-
=> await _testParser.InvokeAsync(parseResult.Value, _nullConsole);
60+
=> await parseResult.Value.InvokeAsync(_nullConsole);
6161
}
6262
}

src/System.CommandLine.Rendering.Tests/TerminalModeTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.CommandLine.Builder;
55
using System.CommandLine.Invocation;
66
using System.CommandLine.IO;
7+
using System.CommandLine.Parsing;
78
using System.CommandLine.Tests;
89
using System.Threading.Tasks;
910
using FluentAssertions;

src/System.CommandLine.Suggest.Tests/DotnetSuggestEndToEndTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ await Process.ExecuteAsync(
155155

156156
stdOut.ToString()
157157
.Should()
158-
.Be($"--apple{NewLine}--banana{NewLine}--cherry{NewLine}--durian{NewLine}");
158+
.Be($"--apple{NewLine}--banana{NewLine}--cherry{NewLine}--durian{NewLine}--version{NewLine}");
159159
}
160160
}
161161
}

src/System.CommandLine.Suggest.Tests/EndToEndTestApp/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.CommandLine;
33
using System.CommandLine.Builder;
44
using System.CommandLine.Invocation;
5+
using System.CommandLine.Parsing;
56
using System.Threading.Tasks;
67

78
namespace EndToEndTestApp
@@ -33,10 +34,7 @@ static async Task Main(string[] args)
3334
rootCommand.Handler = CommandHandler.Create(typeof(Program).GetMethod(nameof(Run)));
3435

3536
var commandLine = new CommandLineBuilder(rootCommand)
36-
.UseHelp()
37-
.UseSuggestDirective()
38-
.UseExceptionHandler()
39-
.RegisterWithDotnetSuggest()
37+
.UseDefaults()
4038
.Build();
4139

4240
await commandLine.InvokeAsync(args);

src/System.CommandLine.Tests/Help/HelpBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using System.Collections.Generic;
55
using System.CommandLine.Builder;
66
using System.CommandLine.Help;
7-
using System.CommandLine.Invocation;
87
using System.CommandLine.IO;
8+
using System.CommandLine.Parsing;
99
using System.IO;
1010
using FluentAssertions;
1111
using System.Linq;

src/System.CommandLine.Tests/Invocation/CancelOnProcessTerminationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.CommandLine.Builder;
55
using System.CommandLine.Invocation;
6+
using System.CommandLine.Parsing;
67
using System.Diagnostics;
78
using System.Runtime.InteropServices;
89
using System.Threading;

src/System.CommandLine.Tests/Invocation/TypoCorrectionTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task When_option_is_mistyped_it_is_suggested()
2525

2626
var result = parser.Parse("niof");
2727

28-
await parser.InvokeAsync(result, _console);
28+
await result.InvokeAsync(_console);
2929

3030
_console.Out.ToString().Should().Contain("'niof' was not matched. Did you mean 'info'?");
3131
}
@@ -43,7 +43,7 @@ public async Task When_there_are_no_matches_then_nothing_is_suggested()
4343

4444
var result = parser.Parse("zzzzzzz");
4545

46-
await parser.InvokeAsync(result, _console);
46+
await result.InvokeAsync(_console);
4747

4848
_console.Out.ToString().Should().NotContain("was not matched");
4949
}
@@ -61,7 +61,7 @@ public async Task When_command_is_mistyped_it_is_suggested()
6161

6262
var result = parser.Parse("sertor");
6363

64-
await parser.InvokeAsync(result, _console);
64+
await result.InvokeAsync(_console);
6565

6666
_console.Out.ToString().Should().Contain("'sertor' was not matched. Did you mean 'restore'?");
6767
}
@@ -80,7 +80,7 @@ public async Task When_there_are_multiple_matches_it_picks_the_best_matches()
8080

8181
var result = parser.Parse("een");
8282

83-
await parser.InvokeAsync(result, _console);
83+
await result.InvokeAsync(_console);
8484

8585
_console.Out.ToString().Should().Contain("'een' was not matched. Did you mean 'seen', or 'been'?");
8686
}
@@ -98,7 +98,7 @@ public async Task Hidden_commands_are_not_suggested()
9898

9999
var result = parser.Parse("een");
100100

101-
await parser.InvokeAsync(result, _console);
101+
await result.InvokeAsync(_console);
102102

103103
_console.Out.ToString().Should().Contain("'een' was not matched. Did you mean 'been'?");
104104
}
@@ -115,7 +115,7 @@ public async Task Arguments_are_not_suggested()
115115

116116
var result = parser.Parse("een");
117117

118-
await parser.InvokeAsync(result, _console);
118+
await result.InvokeAsync(_console);
119119

120120
_console.Out.ToString().Should().Contain("'een' was not matched. Did you mean 'been'?");
121121
}
@@ -132,7 +132,7 @@ public async Task Hidden_options_are_not_suggested()
132132
.Build();
133133
var result = parser.Parse("een");
134134

135-
await parser.InvokeAsync(result, _console);
135+
await result.InvokeAsync(_console);
136136

137137
_console.Out.ToString().Should().Contain("'een' was not matched. Did you mean 'been'?");
138138
}
@@ -148,7 +148,7 @@ public async Task Suggestions_favor_matches_with_prefix()
148148
.Build();
149149
var result = parser.Parse("-all");
150150

151-
await parser.InvokeAsync(result, _console);
151+
await result.InvokeAsync(_console);
152152

153153
_console.Out.ToString().Should().Contain("'-all' was not matched. Did you mean '-call'?");
154154
}

src/System.CommandLine.Tests/ParseDirectiveTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task Parse_directive_writes_parse_diagram()
4343

4444
var console = new TestConsole();
4545

46-
await parser.InvokeAsync(result, console);
46+
await result.InvokeAsync(console);
4747

4848
console.Out
4949
.ToString()

src/System.CommandLine.Tests/SuggestDirectiveTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task It_writes_suggestions_for_option_arguments_when_under_subcomma
5656

5757
var console = new TestConsole();
5858

59-
await parser.InvokeAsync(result, console);
59+
await result.InvokeAsync(console);
6060

6161
console.Out
6262
.ToString()
@@ -81,7 +81,7 @@ public async Task It_writes_suggestions_for_option_arguments_when_under_root_com
8181

8282
var console = new TestConsole();
8383

84-
await parser.InvokeAsync(result, console);
84+
await result.InvokeAsync(console);
8585

8686
console.Out
8787
.ToString()
@@ -107,7 +107,7 @@ public async Task It_writes_suggestions_for_option_aliases_under_subcommand(stri
107107

108108
var console = new TestConsole();
109109

110-
await parser.InvokeAsync(result, console);
110+
await result.InvokeAsync(console);
111111

112112
console.Out
113113
.ToString()
@@ -136,7 +136,7 @@ public async Task It_writes_suggestions_for_option_aliases_under_root_command(st
136136

137137
var console = new TestConsole();
138138

139-
await parser.InvokeAsync(result, console);
139+
await result.InvokeAsync(console);
140140

141141
console.Out
142142
.ToString()
@@ -160,7 +160,7 @@ public async Task It_writes_suggestions_for_subcommand_aliases_under_root_comman
160160

161161
var console = new TestConsole();
162162

163-
await parser.InvokeAsync(result, console);
163+
await result.InvokeAsync(console);
164164

165165
console.Out
166166
.ToString()
@@ -185,7 +185,7 @@ public async Task It_writes_suggestions_for_partial_option_aliases_under_root_co
185185

186186
var console = new TestConsole();
187187

188-
await parser.InvokeAsync(result, console);
188+
await result.InvokeAsync(console);
189189

190190
console.Out
191191
.ToString()
@@ -206,7 +206,7 @@ public async Task It_writes_suggestions_for_partial_subcommand_aliases_under_roo
206206

207207
var console = new TestConsole();
208208

209-
await parser.InvokeAsync(result, console);
209+
await result.InvokeAsync(console);
210210

211211
console.Out
212212
.ToString()
@@ -227,7 +227,7 @@ public async Task It_writes_suggestions_for_partial_option_and_subcommand_aliase
227227

228228
var console = new TestConsole();
229229

230-
await parser.InvokeAsync(result, console);
230+
await result.InvokeAsync(console);
231231

232232
console.Out
233233
.ToString()

src/System.CommandLine.Tests/UseExceptionHandlerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.CommandLine.Builder;
55
using System.CommandLine.Invocation;
66
using System.CommandLine.IO;
7+
using System.CommandLine.Parsing;
78
using System.Threading.Tasks;
89
using FluentAssertions;
910
using Xunit;

0 commit comments

Comments
 (0)