Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace IConsole with two TextWriters in Configuration #2106

Merged
merged 10 commits into from
Mar 24, 2023
3 changes: 2 additions & 1 deletion samples/RenderingPlayground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.Rendering;
using System.CommandLine.Rendering.Views;
using System.IO;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static void Main(
height ?? Console.WindowHeight,
overwrite);

var console = invocationContext.Console;
var console = new SystemConsole();

if (overwrite &&
console is ITerminal terminal)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
System.CommandLine.Binding
public class BindingContext, System.IServiceProvider
public System.CommandLine.IConsole Console { get; }
public System.CommandLine.ParseResult ParseResult { get; }
public System.Void AddService(System.Type serviceType, System.Func<System.IServiceProvider,System.Object> factory)
public System.Void AddService<T>(Func<System.IServiceProvider,T> factory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ System.CommandLine
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
public System.Void SetAction(System.Action<System.CommandLine.Invocation.InvocationContext> action)
public System.Void SetAction(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> action)
public static class CommandExtensions
public static System.Int32 Invoke(this Command command, System.String[] args, IConsole console = null)
public static System.Int32 Invoke(this Command command, System.String commandLine, IConsole console = null)
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Command command, System.String[] args, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Command command, System.String commandLine, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public class CommandLineBuilder
.ctor(Command rootCommand)
public Command Command { get; }
Expand All @@ -85,11 +80,13 @@ System.CommandLine
public System.Collections.Generic.IReadOnlyList<Directive> Directives { get; }
public System.Boolean EnablePosixBundling { get; }
public System.Boolean EnableTokenReplacement { get; }
public System.IO.TextWriter Error { get; set; }
public System.IO.TextWriter Output { get; set; }
public Command RootCommand { get; }
public System.Int32 Invoke(System.String commandLine, IConsole console = null)
public System.Int32 Invoke(System.String[] args, IConsole console = null)
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String commandLine, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String[] args, IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public System.Int32 Invoke(System.String commandLine)
public System.Int32 Invoke(System.String[] args)
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String commandLine, System.Threading.CancellationToken cancellationToken = null)
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String[] args, System.Threading.CancellationToken cancellationToken = null)
public System.Void ThrowIfInvalid()
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
.ctor(System.String message)
Expand All @@ -105,7 +102,6 @@ System.CommandLine
public class EnvironmentVariablesDirective : Directive
.ctor()
public CliAction Action { get; set; }
public interface IConsole : System.CommandLine.IO.IStandardError, System.CommandLine.IO.IStandardIn, System.CommandLine.IO.IStandardOut
public abstract class Option : Symbol, System.CommandLine.Binding.IValueDescriptor
public CliAction Action { get; set; }
public System.Collections.Generic.ICollection<System.String> Aliases { get; }
Expand Down Expand Up @@ -151,8 +147,8 @@ System.CommandLine
public T GetValue<T>(Argument<T> argument)
public T GetValue<T>(Option<T> option)
public T GetValue<T>(System.String name)
public System.Int32 Invoke(IConsole console = null)
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public System.Int32 Invoke()
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.Threading.CancellationToken cancellationToken = null)
public System.String ToString()
public class RootCommand : Command, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable
public static System.String ExecutableName { get; }
Expand Down Expand Up @@ -247,46 +243,10 @@ System.CommandLine.Help
public System.Int32 GetHashCode()
System.CommandLine.Invocation
public class InvocationContext
.ctor(System.CommandLine.ParseResult parseResult, System.CommandLine.IConsole console = null)
public System.CommandLine.IConsole Console { get; set; }
.ctor(System.CommandLine.ParseResult parseResult)
public System.CommandLine.ParseResult ParseResult { get; set; }
public T GetValue<T>(Option<T> option)
public T GetValue<T>(Argument<T> argument)
System.CommandLine.IO
public interface IStandardError
public IStandardStreamWriter Error { get; }
public System.Boolean IsErrorRedirected { get; }
public interface IStandardIn
public System.Boolean IsInputRedirected { get; }
public interface IStandardOut
public System.Boolean IsOutputRedirected { get; }
public IStandardStreamWriter Out { get; }
public interface IStandardStreamWriter
public System.Void Write(System.String value)
public static class StandardStreamWriter
public static IStandardStreamWriter Create(System.IO.TextWriter writer)
public static System.IO.TextWriter CreateTextWriter(this IStandardStreamWriter writer)
public static System.Void WriteLine(this IStandardStreamWriter writer)
public static System.Void WriteLine(this IStandardStreamWriter writer, System.String value)
public class SystemConsole, System.CommandLine.IConsole, IStandardError, IStandardIn, IStandardOut
.ctor()
public IStandardStreamWriter Error { get; }
public System.Boolean IsErrorRedirected { get; }
public System.Boolean IsInputRedirected { get; }
public System.Boolean IsOutputRedirected { get; }
public IStandardStreamWriter Out { get; }
public class TestConsole, System.CommandLine.IConsole, IStandardError, IStandardIn, IStandardOut
.ctor()
public IStandardStreamWriter Error { get; }
public System.Boolean IsErrorRedirected { get; }
public System.Boolean IsInputRedirected { get; }
public System.Boolean IsOutputRedirected { get; }
public IStandardStreamWriter Out { get; }
protected System.Void set_Error(IStandardStreamWriter value)
protected System.Void set_IsErrorRedirected(System.Boolean value)
protected System.Void set_IsInputRedirected(System.Boolean value)
protected System.Void set_IsOutputRedirected(System.Boolean value)
protected System.Void set_Out(IStandardStreamWriter value)
System.CommandLine.Parsing
public class ArgumentResult : SymbolResult
public System.CommandLine.Argument Argument { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ namespace System.CommandLine.Benchmarks.CommandLine
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_Directives_Suggest
{
private NullConsole _nullConsole;
private CommandLineConfiguration _configuration;

[GlobalSetup]
public void Setup()
{
_nullConsole = new NullConsole();

Option<string> fruitOption = new("--fruit");
fruitOption.CompletionSources.Add("apple", "banana", "cherry");

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

[Params(
Expand All @@ -47,7 +45,7 @@ public void Setup()

[Benchmark]
public Task InvokeSuggest()
=> _configuration.InvokeAsync(TestCmdArgs, _nullConsole);
=> _configuration.InvokeAsync(TestCmdArgs);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class Perf_Parser_Simple
public string[] Args { get; set; }

[Benchmark]
public int DefaultsSync() => BuildCommand().Invoke(Args);
public int DefaultsSync() => BuildCommand().Parse(Args).Invoke();

[Benchmark]
public Task<int> DefaultsAsync() => BuildCommand().InvokeAsync(Args);
public Task<int> DefaultsAsync() => BuildCommand().Parse(Args).InvokeAsync();

[Benchmark]
public int MinimalSync() => new CommandLineBuilder(BuildCommand()).Build().Invoke(Args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections.Generic;
using System.CommandLine.Benchmarks.Helpers;
using System.CommandLine.Parsing;
using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
Expand All @@ -16,7 +15,6 @@ namespace System.CommandLine.Benchmarks.CommandLine
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_TypoCorrection
{
private readonly NullConsole _nullConsole = new();
private readonly CommandLineConfiguration _configuration;

public Perf_Parser_TypoCorrection()
Expand All @@ -26,6 +24,7 @@ public Perf_Parser_TypoCorrection()
_configuration = new CommandLineBuilder(new RootCommand { option })
.UseTypoCorrections()
.Build();
_configuration.Output = System.IO.TextWriter.Null;
}

public IEnumerable<BdnParam<ParseResult>> GenerateTestParseResults()
Expand Down Expand Up @@ -54,6 +53,6 @@ public IEnumerable<BdnParam<ParseResult>> GenerateTestParseResults()
[Benchmark]
[ArgumentsSource(nameof(GenerateTestParseResults))]
public Task TypoCorrection(BdnParam<ParseResult> parseResult)
=> parseResult.Value.InvokeAsync(_nullConsole);
=> parseResult.Value.InvokeAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace System.CommandLine.Benchmarks.DragonFruit
[InvocationCount(3000)]
public class Perf_CommandLine_EntryPoint
{
private readonly NullConsole _nullConsole = new();
private Assembly _testAssembly;
private string _testAssemblyFilePath;
private string _testAssemblyXmlDocsFilePath;
Expand Down Expand Up @@ -134,17 +133,15 @@ public Task SearchForStartingPointUsingReflection()
_testAssembly,
new string[] { },
null,
_testAssemblyXmlDocsFilePath,
_nullConsole);
_testAssemblyXmlDocsFilePath);

[Benchmark(Description = "ExecuteAssemblyAsync explicit entry point.")]
public Task SearchForStartingPointWhenGivenEntryPointClass()
=> System.CommandLine.DragonFruit.CommandLine.ExecuteAssemblyAsync(
_testAssembly,
new string[] { },
"PerfTestApp.Program",
_testAssemblyXmlDocsFilePath,
_nullConsole);
_testAssemblyXmlDocsFilePath);

[GlobalCleanup]
public void Cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace System.CommandLine.Benchmarks.DragonFruit
[InvocationCount(3000)]
public class Perf_CommandLine_Help
{
private readonly NullConsole _nullConsole = new();
private Assembly _testAssembly;
private string _testAssemblyFilePath;
private string _testAssemblyXmlDocsFilePath;
Expand All @@ -44,8 +43,7 @@ public Task SearchForStartingPointWhenGivenEntryPointClass_Help()
_testAssembly,
new[] { "--help" },
null,
_testAssemblyXmlDocsFilePath,
_nullConsole);
_testAssemblyXmlDocsFilePath);

[GlobalCleanup]
public void Cleanup()
Expand Down
19 changes: 0 additions & 19 deletions src/System.CommandLine.Benchmarks/Helpers/NullConsole.cs

This file was deleted.

Loading