Skip to content

rename Parser to CliParser and CommandLineConfiguration to CliConfiguration #2136

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

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/HostingPlayground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ static Task Main(string[] args) => BuildCommandLine()
})
.InvokeAsync(args);

private static CommandLineConfiguration BuildCommandLine()
private static CliConfiguration BuildCommandLine()
{
var root = new CliRootCommand(@"$ dotnet run --name 'Joe'"){
new CliOption<string>("--name"){
Required = true
}
};
root.Action = CommandHandler.Create<GreeterOptions, IHost>(Run);
return new CommandLineConfiguration(root);
return new CliConfiguration(root);
}

private static void Run(GreeterOptions options, IHost host)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ System.CommandLine.Hosting
public static System.CommandLine.ParseResult GetParseResult(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder)
public static System.CommandLine.ParseResult GetParseResult(this Microsoft.Extensions.Hosting.HostBuilderContext context)
public static System.CommandLine.CliCommand UseCommandHandler<THandler>(this System.CommandLine.CliCommand command)
public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Func<System.String[],Microsoft.Extensions.Hosting.IHostBuilder> hostBuilderFactory, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static System.CommandLine.CliConfiguration UseHost(this System.CommandLine.CliConfiguration builder, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static System.CommandLine.CliConfiguration UseHost(this System.CommandLine.CliConfiguration builder, System.Func<System.String[],Microsoft.Extensions.Hosting.IHostBuilder> hostBuilderFactory, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.Action<InvocationLifetimeOptions> configureOptions = null)
public class InvocationLifetime, Microsoft.Extensions.Hosting.IHostLifetime
.ctor(Microsoft.Extensions.Options.IOptions<InvocationLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,31 @@ System.CommandLine
public System.Void Add(CliSymbol symbol)
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Collections.Generic.IEnumerator<CliSymbol> GetEnumerator()
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CommandLineConfiguration configuration = null)
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CliConfiguration configuration = null)
public ParseResult Parse(System.String commandLine, CliConfiguration configuration = null)
public System.Void SetAction(System.Action<ParseResult> action)
public System.Void SetAction(System.Func<ParseResult,System.Int32> action)
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task> action)
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Int32>> action)
public class CliConfiguration
.ctor(CliCommand rootCommand)
public System.Collections.Generic.List<CliDirective> Directives { get; }
public System.Boolean EnableDefaultExceptionHandler { get; set; }
public System.Boolean EnableParseErrorReporting { get; set; }
public System.Boolean EnablePosixBundling { get; set; }
public System.Boolean EnableTypoCorrections { get; set; }
public System.IO.TextWriter Error { get; set; }
public System.IO.TextWriter Output { get; set; }
public System.Nullable<System.TimeSpan> ProcessTerminationTimeout { get; set; }
public System.CommandLine.Parsing.TryReplaceToken ResponseFileTokenReplacer { get; set; }
public CliCommand RootCommand { get; }
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 ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args)
public ParseResult Parse(System.String commandLine)
public System.Void ThrowIfInvalid()
public class CliDirective : CliSymbol
.ctor(System.String name)
public CliAction Action { get; set; }
Expand Down Expand Up @@ -92,25 +111,6 @@ System.CommandLine
public System.Collections.Generic.IEnumerable<CliSymbol> Parents { get; }
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.String ToString()
public class CommandLineConfiguration
.ctor(CliCommand rootCommand)
public System.Collections.Generic.List<CliDirective> Directives { get; }
public System.Boolean EnableDefaultExceptionHandler { get; set; }
public System.Boolean EnableParseErrorReporting { get; set; }
public System.Boolean EnablePosixBundling { get; set; }
public System.Boolean EnableTypoCorrections { get; set; }
public System.IO.TextWriter Error { get; set; }
public System.IO.TextWriter Output { get; set; }
public System.Nullable<System.TimeSpan> ProcessTerminationTimeout { get; set; }
public System.CommandLine.Parsing.TryReplaceToken ResponseFileTokenReplacer { get; set; }
public CliCommand RootCommand { get; }
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 ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args)
public ParseResult Parse(System.String commandLine)
public System.Void ThrowIfInvalid()
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
.ctor(System.String message)
public static class CompletionSourceExtensions
Expand All @@ -131,7 +131,7 @@ System.CommandLine
public class ParseResult
public CliAction Action { get; }
public System.CommandLine.Parsing.CommandResult CommandResult { get; }
public CommandLineConfiguration Configuration { get; }
public CliConfiguration Configuration { get; }
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.ParseError> Errors { get; }
public System.CommandLine.Parsing.CommandResult RootCommandResult { get; }
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.Token> Tokens { get; }
Expand Down Expand Up @@ -234,6 +234,10 @@ System.CommandLine.Parsing
public T GetValueOrDefault<T>()
public System.Void OnlyTake(System.Int32 numberOfTokens)
public System.String ToString()
public static class CliParser
public static System.CommandLine.ParseResult Parse(System.CommandLine.CliCommand command, System.Collections.Generic.IReadOnlyList<System.String> args, System.CommandLine.CliConfiguration configuration = null)
public static System.CommandLine.ParseResult Parse(System.CommandLine.CliCommand command, System.String commandLine, System.CommandLine.CliConfiguration configuration = null)
public static System.Collections.Generic.IEnumerable<System.String> SplitCommandLine(System.String commandLine)
public class CommandResult : SymbolResult
public System.Collections.Generic.IEnumerable<SymbolResult> Children { get; }
public System.CommandLine.CliCommand Command { get; }
Expand All @@ -253,10 +257,6 @@ System.CommandLine.Parsing
public System.String Message { get; }
public SymbolResult SymbolResult { get; }
public System.String ToString()
public static class Parser
public static System.CommandLine.ParseResult Parse(System.CommandLine.CliCommand command, System.Collections.Generic.IReadOnlyList<System.String> args, System.CommandLine.CommandLineConfiguration configuration = null)
public static System.CommandLine.ParseResult Parse(System.CommandLine.CliCommand command, System.String commandLine, System.CommandLine.CommandLineConfiguration configuration = null)
public static System.Collections.Generic.IEnumerable<System.String> SplitCommandLine(System.String commandLine)
public abstract class SymbolResult
public SymbolResult Parent { get; }
public System.Collections.Generic.IReadOnlyList<Token> Tokens { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
namespace System.CommandLine.Benchmarks.CommandLine
{
/// <summary>
/// Measures the performance of <see cref="Parser"/> for custom scenarios.
/// Measures the performance of <see cref="CliParser"/> for custom scenarios.
/// </summary>
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_CustomScenarios
{
private string _testSymbolsAsString;
private CliCommand _rootCommand;
private CommandLineConfiguration _configuration;
private CliConfiguration _configuration;

[GlobalSetup(Target = nameof(OneOptWithNestedCommand_Parse))]
public void SetupOneOptWithNestedCommand()
Expand All @@ -26,7 +26,7 @@ public void SetupOneOptWithNestedCommand()
_rootCommand.Subcommands.Add(nestedCommand);

_testSymbolsAsString = "root_command nested_command -opt1 321";
_configuration = new CommandLineConfiguration(_rootCommand);
_configuration = new CliConfiguration(_rootCommand);
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.CommandLine.Benchmarks.CommandLine
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_Directives_Suggest
{
private CommandLineConfiguration _configuration;
private CliConfiguration _configuration;

[GlobalSetup]
public void Setup()
Expand All @@ -30,7 +30,7 @@ public void Setup()
vegetableOption
};

_configuration = new CommandLineConfiguration(eatCommand)
_configuration = new CliConfiguration(eatCommand)
{
Directives = { new SuggestDirective() },
Output = System.IO.TextWriter.Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
namespace System.CommandLine.Benchmarks.CommandLine
{
/// <summary>
/// Measures the performance of <see cref="Parser"/> when parsing commands.
/// Measures the performance of <see cref="CliParser"/> when parsing commands.
/// </summary>
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_NestedCommands
{
private string _testSymbolsAsString;
private CliCommand _rootCommand;
private CommandLineConfiguration _configuration;
private CliConfiguration _configuration;

/// <remarks>
/// 1 - cmd-root
Expand Down Expand Up @@ -62,10 +62,10 @@ public void SetupRootCommand()
}

_rootCommand = rootCommand;
_configuration = new CommandLineConfiguration(rootCommand);
_configuration = new CliConfiguration(rootCommand);
}

[Benchmark]
public ParseResult Parser_Parse() => Parser.Parse(_rootCommand, _testSymbolsAsString, _configuration);
public ParseResult Parser_Parse() => CliParser.Parse(_rootCommand, _testSymbolsAsString, _configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
namespace System.CommandLine.Benchmarks.CommandLine
{
/// <summary>
/// Measures the performance of <see cref="Parser"/> when parsing options without arguments.
/// Measures the performance of <see cref="CliParser"/> when parsing options without arguments.
/// </summary>
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_Options_Bare
{
private IEnumerable<CliOption> _testSymbols;
private string _testSymbolsAsString;
private CommandLineConfiguration _testConfiguration;
private CliConfiguration _testConfiguration;

private IEnumerable<CliOption> GenerateTestOptions(int count, ArgumentArity arity)
=> Enumerable.Range(0, count)
Expand Down Expand Up @@ -49,7 +49,7 @@ public void SetupTestOptions()
}

[Benchmark]
public CommandLineConfiguration ParserFromOptions_Ctor()
public CliConfiguration ParserFromOptions_Ctor()
{
return _testSymbols.CreateConfiguration();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
namespace System.CommandLine.Benchmarks.CommandLine
{
/// <summary>
/// Measures the performance of <see cref="Parser"/> when parsing options with arguments.
/// Measures the performance of <see cref="CliParser"/> when parsing options with arguments.
/// </summary>
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_Options_With_Arguments
{
private string _testSymbolsAsString;
private CommandLineConfiguration _configuration;
private CliConfiguration _configuration;

private IEnumerable<CliOption> GenerateTestOptions(int count, ArgumentArity arity)
=> Enumerable.Range(0, count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ namespace System.CommandLine.Benchmarks.CommandLine
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_ParseResult
{
private readonly CommandLineConfiguration _configuration;
private readonly CliConfiguration _configuration;
private readonly StringWriter _output;

public Perf_Parser_ParseResult()
{
_output = new StringWriter();
var option = new CliOption<bool>("-opt");

_configuration = new CommandLineConfiguration(new CliRootCommand { option })
_configuration = new CliConfiguration(new CliRootCommand { option })
{
Directives = { new ParseDiagramDirective() },
Output = _output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private static CliRootCommand BuildCommand()
return command;
}

private static CommandLineConfiguration BuildMinimalConfig(CliCommand command)
private static CliConfiguration BuildMinimalConfig(CliCommand command)
{
CommandLineConfiguration config = new(command);
CliConfiguration config = new(command);
config.Directives.Clear();
config.EnableDefaultExceptionHandler = false;
config.ProcessTerminationTimeout = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace System.CommandLine.Benchmarks.CommandLine
[BenchmarkCategory(Categories.CommandLine)]
public class Perf_Parser_TypoCorrection
{
private readonly CommandLineConfiguration _configuration;
private readonly CliConfiguration _configuration;

public Perf_Parser_TypoCorrection()
{
var option = new CliOption<bool>("--0123456789");

_configuration = new CommandLineConfiguration(new CliRootCommand { option })
_configuration = new CliConfiguration(new CliRootCommand { option })
{
EnableTypoCorrections = true,
Output = System.IO.TextWriter.Null
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Benchmarks/Helpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static string CreateTestAssemblyInTempFileFromString(string sourceCode,
return pathToAssemblyFile;
}

public static CommandLineConfiguration CreateConfiguration(this IEnumerable<CliOption> symbols)
public static CliConfiguration CreateConfiguration(this IEnumerable<CliOption> symbols)
{
var rootCommand = new CliRootCommand();

Expand All @@ -53,7 +53,7 @@ public static CommandLineConfiguration CreateConfiguration(this IEnumerable<CliO
rootCommand.Add(symbol);
}

return new CommandLineConfiguration(rootCommand);
return new CliConfiguration(rootCommand);
}
}
}
Loading