Skip to content

Commit b90bff7

Browse files
authored
replace IConsole with two TextWriters in Configuration (#2106)
1 parent 0403596 commit b90bff7

File tree

68 files changed

+540
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+540
-859
lines changed

samples/RenderingPlayground/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.CommandLine.Invocation;
6+
using System.CommandLine.IO;
67
using System.CommandLine.Rendering;
78
using System.CommandLine.Rendering.Views;
89
using System.IO;
@@ -44,7 +45,7 @@ public static void Main(
4445
height ?? Console.WindowHeight,
4546
overwrite);
4647

47-
var console = invocationContext.Console;
48+
var console = new SystemConsole();
4849

4950
if (overwrite &&
5051
console is ITerminal terminal)

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
System.CommandLine.Binding
22
public class BindingContext, System.IServiceProvider
3-
public System.CommandLine.IConsole Console { get; }
43
public System.CommandLine.ParseResult ParseResult { get; }
54
public System.Void AddService(System.Type serviceType, System.Func<System.IServiceProvider,System.Object> factory)
65
public System.Void AddService<T>(Func<System.IServiceProvider,T> factory)

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ System.CommandLine
5555
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
5656
public System.Void SetAction(System.Action<System.CommandLine.Invocation.InvocationContext> action)
5757
public System.Void SetAction(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> action)
58-
public static class CommandExtensions
59-
public static System.Int32 Invoke(this Command command, System.String[] args, IConsole console = null)
60-
public static System.Int32 Invoke(this Command command, System.String commandLine, IConsole console = null)
61-
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Command command, System.String[] args, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
62-
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Command command, System.String commandLine, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
6358
public class CommandLineBuilder
6459
.ctor(Command rootCommand)
6560
public Command Command { get; }
@@ -85,11 +80,13 @@ System.CommandLine
8580
public System.Collections.Generic.IReadOnlyList<Directive> Directives { get; }
8681
public System.Boolean EnablePosixBundling { get; }
8782
public System.Boolean EnableTokenReplacement { get; }
83+
public System.IO.TextWriter Error { get; set; }
84+
public System.IO.TextWriter Output { get; set; }
8885
public Command RootCommand { get; }
89-
public System.Int32 Invoke(System.String commandLine, IConsole console = null)
90-
public System.Int32 Invoke(System.String[] args, IConsole console = null)
91-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String commandLine, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
92-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String[] args, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
86+
public System.Int32 Invoke(System.String commandLine)
87+
public System.Int32 Invoke(System.String[] args)
88+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String commandLine, System.Threading.CancellationToken cancellationToken = null)
89+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String[] args, System.Threading.CancellationToken cancellationToken = null)
9390
public System.Void ThrowIfInvalid()
9491
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
9592
.ctor(System.String message)
@@ -105,7 +102,6 @@ System.CommandLine
105102
public class EnvironmentVariablesDirective : Directive
106103
.ctor()
107104
public CliAction Action { get; set; }
108-
public interface IConsole : System.CommandLine.IO.IStandardError, System.CommandLine.IO.IStandardIn, System.CommandLine.IO.IStandardOut
109105
public abstract class Option : Symbol, System.CommandLine.Binding.IValueDescriptor
110106
public CliAction Action { get; set; }
111107
public System.Collections.Generic.ICollection<System.String> Aliases { get; }
@@ -151,8 +147,8 @@ System.CommandLine
151147
public T GetValue<T>(Argument<T> argument)
152148
public T GetValue<T>(Option<T> option)
153149
public T GetValue<T>(System.String name)
154-
public System.Int32 Invoke(IConsole console = null)
155-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
150+
public System.Int32 Invoke()
151+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.Threading.CancellationToken cancellationToken = null)
156152
public System.String ToString()
157153
public class RootCommand : Command, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable
158154
public static System.String ExecutableName { get; }
@@ -247,46 +243,10 @@ System.CommandLine.Help
247243
public System.Int32 GetHashCode()
248244
System.CommandLine.Invocation
249245
public class InvocationContext
250-
.ctor(System.CommandLine.ParseResult parseResult, System.CommandLine.IConsole console = null)
251-
public System.CommandLine.IConsole Console { get; set; }
246+
.ctor(System.CommandLine.ParseResult parseResult)
252247
public System.CommandLine.ParseResult ParseResult { get; set; }
253248
public T GetValue<T>(Option<T> option)
254249
public T GetValue<T>(Argument<T> argument)
255-
System.CommandLine.IO
256-
public interface IStandardError
257-
public IStandardStreamWriter Error { get; }
258-
public System.Boolean IsErrorRedirected { get; }
259-
public interface IStandardIn
260-
public System.Boolean IsInputRedirected { get; }
261-
public interface IStandardOut
262-
public System.Boolean IsOutputRedirected { get; }
263-
public IStandardStreamWriter Out { get; }
264-
public interface IStandardStreamWriter
265-
public System.Void Write(System.String value)
266-
public static class StandardStreamWriter
267-
public static IStandardStreamWriter Create(System.IO.TextWriter writer)
268-
public static System.IO.TextWriter CreateTextWriter(this IStandardStreamWriter writer)
269-
public static System.Void WriteLine(this IStandardStreamWriter writer)
270-
public static System.Void WriteLine(this IStandardStreamWriter writer, System.String value)
271-
public class SystemConsole, System.CommandLine.IConsole, IStandardError, IStandardIn, IStandardOut
272-
.ctor()
273-
public IStandardStreamWriter Error { get; }
274-
public System.Boolean IsErrorRedirected { get; }
275-
public System.Boolean IsInputRedirected { get; }
276-
public System.Boolean IsOutputRedirected { get; }
277-
public IStandardStreamWriter Out { get; }
278-
public class TestConsole, System.CommandLine.IConsole, IStandardError, IStandardIn, IStandardOut
279-
.ctor()
280-
public IStandardStreamWriter Error { get; }
281-
public System.Boolean IsErrorRedirected { get; }
282-
public System.Boolean IsInputRedirected { get; }
283-
public System.Boolean IsOutputRedirected { get; }
284-
public IStandardStreamWriter Out { get; }
285-
protected System.Void set_Error(IStandardStreamWriter value)
286-
protected System.Void set_IsErrorRedirected(System.Boolean value)
287-
protected System.Void set_IsInputRedirected(System.Boolean value)
288-
protected System.Void set_IsOutputRedirected(System.Boolean value)
289-
protected System.Void set_Out(IStandardStreamWriter value)
290250
System.CommandLine.Parsing
291251
public class ArgumentResult : SymbolResult
292252
public System.CommandLine.Argument Argument { get; }

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Directives_Suggest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ namespace System.CommandLine.Benchmarks.CommandLine
1414
[BenchmarkCategory(Categories.CommandLine)]
1515
public class Perf_Parser_Directives_Suggest
1616
{
17-
private NullConsole _nullConsole;
1817
private CommandLineConfiguration _configuration;
1918

2019
[GlobalSetup]
2120
public void Setup()
2221
{
23-
_nullConsole = new NullConsole();
24-
2522
Option<string> fruitOption = new("--fruit");
2623
fruitOption.CompletionSources.Add("apple", "banana", "cherry");
2724

@@ -37,6 +34,7 @@ public void Setup()
3734
_configuration = new CommandLineBuilder(eatCommand)
3835
.UseSuggestDirective()
3936
.Build();
37+
_configuration.Output = System.IO.TextWriter.Null;
4038
}
4139

4240
[Params(
@@ -47,7 +45,7 @@ public void Setup()
4745

4846
[Benchmark]
4947
public Task InvokeSuggest()
50-
=> _configuration.InvokeAsync(TestCmdArgs, _nullConsole);
48+
=> _configuration.InvokeAsync(TestCmdArgs);
5149

5250
}
5351
}

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Simple.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public class Perf_Parser_Simple
1111
public string[] Args { get; set; }
1212

1313
[Benchmark]
14-
public int DefaultsSync() => BuildCommand().Invoke(Args);
14+
public int DefaultsSync() => BuildCommand().Parse(Args).Invoke();
1515

1616
[Benchmark]
17-
public Task<int> DefaultsAsync() => BuildCommand().InvokeAsync(Args);
17+
public Task<int> DefaultsAsync() => BuildCommand().Parse(Args).InvokeAsync();
1818

1919
[Benchmark]
2020
public int MinimalSync() => new CommandLineBuilder(BuildCommand()).Build().Invoke(Args);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Collections.Generic;
55
using System.CommandLine.Benchmarks.Helpers;
6-
using System.CommandLine.Parsing;
76
using System.Linq;
87
using System.Threading.Tasks;
98
using BenchmarkDotNet.Attributes;
@@ -16,7 +15,6 @@ namespace System.CommandLine.Benchmarks.CommandLine
1615
[BenchmarkCategory(Categories.CommandLine)]
1716
public class Perf_Parser_TypoCorrection
1817
{
19-
private readonly NullConsole _nullConsole = new();
2018
private readonly CommandLineConfiguration _configuration;
2119

2220
public Perf_Parser_TypoCorrection()
@@ -26,6 +24,7 @@ public Perf_Parser_TypoCorrection()
2624
_configuration = new CommandLineBuilder(new RootCommand { option })
2725
.UseTypoCorrections()
2826
.Build();
27+
_configuration.Output = System.IO.TextWriter.Null;
2928
}
3029

3130
public IEnumerable<BdnParam<ParseResult>> GenerateTestParseResults()
@@ -54,6 +53,6 @@ public IEnumerable<BdnParam<ParseResult>> GenerateTestParseResults()
5453
[Benchmark]
5554
[ArgumentsSource(nameof(GenerateTestParseResults))]
5655
public Task TypoCorrection(BdnParam<ParseResult> parseResult)
57-
=> parseResult.Value.InvokeAsync(_nullConsole);
56+
=> parseResult.Value.InvokeAsync();
5857
}
5958
}

src/System.CommandLine.Benchmarks/DragonFruit/Perf_CommandLine_EntryPoint.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace System.CommandLine.Benchmarks.DragonFruit
2020
[InvocationCount(3000)]
2121
public class Perf_CommandLine_EntryPoint
2222
{
23-
private readonly NullConsole _nullConsole = new();
2423
private Assembly _testAssembly;
2524
private string _testAssemblyFilePath;
2625
private string _testAssemblyXmlDocsFilePath;
@@ -134,17 +133,15 @@ public Task SearchForStartingPointUsingReflection()
134133
_testAssembly,
135134
new string[] { },
136135
null,
137-
_testAssemblyXmlDocsFilePath,
138-
_nullConsole);
136+
_testAssemblyXmlDocsFilePath);
139137

140138
[Benchmark(Description = "ExecuteAssemblyAsync explicit entry point.")]
141139
public Task SearchForStartingPointWhenGivenEntryPointClass()
142140
=> System.CommandLine.DragonFruit.CommandLine.ExecuteAssemblyAsync(
143141
_testAssembly,
144142
new string[] { },
145143
"PerfTestApp.Program",
146-
_testAssemblyXmlDocsFilePath,
147-
_nullConsole);
144+
_testAssemblyXmlDocsFilePath);
148145

149146
[GlobalCleanup]
150147
public void Cleanup()

src/System.CommandLine.Benchmarks/DragonFruit/Perf_CommandLine_Help.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace System.CommandLine.Benchmarks.DragonFruit
1717
[InvocationCount(3000)]
1818
public class Perf_CommandLine_Help
1919
{
20-
private readonly NullConsole _nullConsole = new();
2120
private Assembly _testAssembly;
2221
private string _testAssemblyFilePath;
2322
private string _testAssemblyXmlDocsFilePath;
@@ -44,8 +43,7 @@ public Task SearchForStartingPointWhenGivenEntryPointClass_Help()
4443
_testAssembly,
4544
new[] { "--help" },
4645
null,
47-
_testAssemblyXmlDocsFilePath,
48-
_nullConsole);
46+
_testAssemblyXmlDocsFilePath);
4947

5048
[GlobalCleanup]
5149
public void Cleanup()

src/System.CommandLine.Benchmarks/Helpers/NullConsole.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)