Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ System.CommandLine
public System.Type ValueType { get; }
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Object GetDefaultValue()
public ParseResult Parse(System.String commandLine)
public ParseResult Parse(System.String[] args)
public System.String ToString()
public class Argument<T> : Argument, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor
.ctor()
Expand Down Expand Up @@ -56,44 +54,48 @@ System.CommandLine
public System.Void Add(Symbol symbol)
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Collections.Generic.IEnumerator<Symbol> GetEnumerator()
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CommandLineConfiguration configuration = null)
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
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 static ParseResult Parse(this Command command, System.String[] args)
public static ParseResult Parse(this Command command, System.String commandLine)
public class CommandLineBuilder
.ctor(Command rootCommand = null)
.ctor(Command rootCommand)
public Command Command { get; }
public System.CommandLine.Parsing.Parser Build()
public static class CommandLineBuilderExtensions
public static CommandLineBuilder AddMiddleware(this CommandLineBuilder builder, System.CommandLine.Invocation.InvocationMiddleware middleware, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public static CommandLineBuilder AddMiddleware(this CommandLineBuilder builder, System.Action<System.CommandLine.Invocation.InvocationContext> onInvoke, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public static CommandLineBuilder CancelOnProcessTermination(this CommandLineBuilder builder, System.Nullable<System.TimeSpan> timeout = null)
public static CommandLineBuilder EnableDirectives(this CommandLineBuilder builder, System.Boolean value = True)
public static CommandLineBuilder EnablePosixBundling(this CommandLineBuilder builder, System.Boolean value = True)
public static CommandLineBuilder RegisterWithDotnetSuggest(this CommandLineBuilder builder)
public static CommandLineBuilder UseDefaults(this CommandLineBuilder builder)
public static CommandLineBuilder UseEnvironmentVariableDirective(this CommandLineBuilder builder)
public static CommandLineBuilder UseExceptionHandler(this CommandLineBuilder builder, System.Action<System.Exception,System.CommandLine.Invocation.InvocationContext> onException = null, System.Nullable<System.Int32> errorExitCode = null)
public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, System.Nullable<System.Int32> maxWidth = null)
public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, System.String[] helpAliases)
public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, System.Action<System.CommandLine.Help.HelpContext> customize, System.Nullable<System.Int32> maxWidth = null)
public static TBuilder UseHelpBuilder<TBuilder>(this TBuilder builder, System.Func<System.CommandLine.Binding.BindingContext,System.CommandLine.Help.HelpBuilder> getHelpBuilder)
public static CommandLineBuilder UseParseDirective(this CommandLineBuilder builder, System.Int32 errorExitCode = 1)
public static CommandLineBuilder UseParseErrorReporting(this CommandLineBuilder builder, System.Int32 errorExitCode = 1)
public static CommandLineBuilder UseSuggestDirective(this CommandLineBuilder builder)
public static CommandLineBuilder UseTokenReplacer(this CommandLineBuilder builder, System.CommandLine.Parsing.TryReplaceToken replaceToken)
public static CommandLineBuilder UseTypoCorrections(this CommandLineBuilder builder, System.Int32 maxLevenshteinDistance = 3)
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder)
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder, System.String[] aliases)
public CommandLineBuilder AddMiddleware(System.CommandLine.Invocation.InvocationMiddleware middleware, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public CommandLineBuilder AddMiddleware(System.Action<System.CommandLine.Invocation.InvocationContext> onInvoke, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public CommandLineConfiguration Build()
public CommandLineBuilder CancelOnProcessTermination(System.Nullable<System.TimeSpan> timeout = null)
public CommandLineBuilder EnableDirectives(System.Boolean value = True)
public CommandLineBuilder EnablePosixBundling(System.Boolean value = True)
public CommandLineBuilder RegisterWithDotnetSuggest()
public CommandLineBuilder UseDefaults()
public CommandLineBuilder UseEnvironmentVariableDirective()
public CommandLineBuilder UseExceptionHandler(System.Action<System.Exception,System.CommandLine.Invocation.InvocationContext> onException = null, System.Nullable<System.Int32> errorExitCode = null)
public CommandLineBuilder UseHelp(System.Nullable<System.Int32> maxWidth = null)
public CommandLineBuilder UseHelp(System.String[] helpAliases)
public CommandLineBuilder UseHelp(System.Action<System.CommandLine.Help.HelpContext> customize, System.Nullable<System.Int32> maxWidth = null)
public CommandLineBuilder UseHelpBuilder(System.Func<System.CommandLine.Binding.BindingContext,System.CommandLine.Help.HelpBuilder> getHelpBuilder)
public CommandLineBuilder UseParseDirective(System.Int32 errorExitCode = 1)
public CommandLineBuilder UseParseErrorReporting(System.Int32 errorExitCode = 1)
public CommandLineBuilder UseSuggestDirective()
public CommandLineBuilder UseTokenReplacer(System.CommandLine.Parsing.TryReplaceToken replaceToken)
public CommandLineBuilder UseTypoCorrections(System.Int32 maxLevenshteinDistance = 3)
public CommandLineBuilder UseVersionOption()
public CommandLineBuilder UseVersionOption(System.String[] aliases)
public class CommandLineConfiguration
public static CommandLineBuilder CreateBuilder(Command rootCommand)
.ctor(Command command, System.Boolean enablePosixBundling = True, System.Boolean enableDirectives = True, System.Boolean enableTokenReplacement = True, System.Collections.Generic.IReadOnlyList<System.CommandLine.Invocation.InvocationMiddleware> middlewarePipeline = null, System.Func<System.CommandLine.Binding.BindingContext,System.CommandLine.Help.HelpBuilder> helpBuilderFactory = null, System.CommandLine.Parsing.TryReplaceToken tokenReplacer = null)
public System.Boolean EnableDirectives { get; }
public System.Boolean EnablePosixBundling { get; }
public System.Boolean EnableTokenReplacement { get; }
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.Void ThrowIfInvalid()
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
.ctor(System.String message)
Expand Down Expand Up @@ -149,8 +151,6 @@ System.CommandLine
public System.Collections.Generic.List<System.Action<System.CommandLine.Parsing.OptionResult>> Validators { get; }
public System.Type ValueType { get; }
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public ParseResult Parse(System.String commandLine)
public ParseResult Parse(System.String[] args)
public class Option<T> : Option, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor
.ctor(System.String name, System.String description = null)
.ctor(System.String[] aliases, System.String description = null)
Expand All @@ -170,9 +170,9 @@ System.CommandLine
public static Option<T> AcceptExistingOnly<T>(this Option<T> option)
public class ParseResult
public System.CommandLine.Parsing.CommandResult CommandResult { get; }
public CommandLineConfiguration Configuration { get; }
public System.Collections.Generic.IReadOnlyDictionary<System.String,System.Collections.Generic.IReadOnlyList<System.String>> Directives { get; }
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.ParseError> Errors { get; }
public System.CommandLine.Parsing.Parser Parser { get; }
public System.CommandLine.Parsing.CommandResult RootCommandResult { get; }
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.Token> Tokens { get; }
public System.Collections.Generic.IReadOnlyList<System.String> UnmatchedTokens { get; }
Expand All @@ -184,6 +184,8 @@ System.CommandLine
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.Nullable<System.Int32> position = null)
public T GetValue<T>(Argument<T> argument)
public T GetValue<T>(Option<T> option)
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.String ToString()
public class RootCommand : Command, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable
public static System.String ExecutableName { get; }
Expand Down Expand Up @@ -286,7 +288,6 @@ System.CommandLine.Invocation
public System.Int32 ExitCode { get; set; }
public System.CommandLine.Help.HelpBuilder HelpBuilder { get; }
public System.Action<InvocationContext> InvocationResult { get; set; }
public System.CommandLine.Parsing.Parser Parser { get; }
public System.CommandLine.ParseResult ParseResult { get; set; }
public T GetValue<T>(Option<T> option)
public T GetValue<T>(Argument<T> argument)
Expand Down Expand Up @@ -359,22 +360,11 @@ System.CommandLine.Parsing
public System.String Message { get; }
public SymbolResult SymbolResult { get; }
public System.String ToString()
public class Parser
.ctor(System.CommandLine.CommandLineConfiguration configuration)
.ctor(System.CommandLine.Command command)
public System.CommandLine.CommandLineConfiguration Configuration { get; }
public System.CommandLine.ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> arguments, System.String rawInput = null)
public static class Parser
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.Collections.Generic.IReadOnlyList<System.String> args, System.CommandLine.CommandLineConfiguration configuration = null)
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.String commandLine, System.CommandLine.CommandLineConfiguration configuration = null)
public static class ParseResultExtensions
public static System.String Diagram(this System.CommandLine.ParseResult parseResult)
public static System.Boolean HasOption(this System.CommandLine.ParseResult parseResult, System.CommandLine.Option option)
public static System.Int32 Invoke(this System.CommandLine.ParseResult parseResult, System.CommandLine.IConsole console = null)
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this System.CommandLine.ParseResult parseResult, System.CommandLine.IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public static class ParserExtensions
public static System.Int32 Invoke(this Parser parser, System.String commandLine, System.CommandLine.IConsole console = null)
public static System.Int32 Invoke(this Parser parser, System.String[] args, System.CommandLine.IConsole console = null)
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Parser parser, System.String commandLine, System.CommandLine.IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public static System.Threading.Tasks.Task<System.Int32> InvokeAsync(this Parser parser, System.String[] args, System.CommandLine.IConsole console = null, System.Threading.CancellationToken cancellationToken = null)
public static System.CommandLine.ParseResult Parse(this Parser parser, 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 @@ -13,23 +13,24 @@ namespace System.CommandLine.Benchmarks.CommandLine
public class Perf_Parser_CustomScenarios
{
private string _testSymbolsAsString;
private Parser _testParser;
private Command _rootCommand;
private CommandLineConfiguration _configuration;

[GlobalSetup(Target = nameof(OneOptWithNestedCommand_Parse))]
public void SetupOneOptWithNestedCommand()
{
var rootCommand = new Command("root_command");
_rootCommand = new Command("root_command");
var nestedCommand = new Command("nested_command");
var option = new Option<int>("-opt1", () => 123);
nestedCommand.Options.Add(option);
rootCommand.Subcommands.Add(nestedCommand);
_rootCommand.Subcommands.Add(nestedCommand);

_testParser = new Parser(rootCommand);
_testSymbolsAsString = "root_command nested_command -opt1 321";
_configuration = CommandLineConfiguration.CreateBuilder(_rootCommand).UseDefaults().Build();
}

[Benchmark]
public ParseResult OneOptWithNestedCommand_Parse()
=> _testParser.Parse(_testSymbolsAsString);
=> _rootCommand.Parse(_testSymbolsAsString, _configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.CommandLine.Benchmarks.CommandLine
public class Perf_Parser_Directives_Suggest
{
private NullConsole _nullConsole;
private Parser _testParser;
private CommandLineConfiguration _configuration;

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

_testParser = new CommandLineBuilder(eatCommand)
_configuration = new CommandLineBuilder(eatCommand)
.UseSuggestDirective()
.Build();
}
Expand All @@ -47,7 +47,7 @@ public void Setup()

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace System.CommandLine.Benchmarks.CommandLine
public class Perf_Parser_NestedCommands
{
private string _testSymbolsAsString;
private Parser _testParser;
private Command _rootCommand;
private CommandLineConfiguration _configuration;

/// <remarks>
/// 1 - cmd-root
Expand Down Expand Up @@ -45,7 +45,7 @@ private void GenerateTestNestedCommands(Command parent, int depth, int countPerL
}
}

[GlobalSetup(Target = nameof(ParserFromNestedCommands_Ctor))]
[GlobalSetup]
public void SetupRootCommand()
{
string rootCommandName = "root";
Expand All @@ -62,19 +62,10 @@ public void SetupRootCommand()
}

_rootCommand = rootCommand;
_configuration = CommandLineConfiguration.CreateBuilder(rootCommand).UseDefaults().Build();
}

[GlobalSetup(Target = nameof(Parser_Parse))]
public void SetupParser()
{
SetupRootCommand();
_testParser = new Parser(_rootCommand);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parser is now static, we can't benchmark it's creation ;)

}

[Benchmark]
public Parser ParserFromNestedCommands_Ctor() => new(_rootCommand);

[Benchmark]
public ParseResult Parser_Parse() => _testParser.Parse(_testSymbolsAsString);
public ParseResult Parser_Parse() => Parser.Parse(_rootCommand, _testSymbolsAsString, _configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Perf_Parser_Options_Bare
{
private IEnumerable<Option> _testSymbols;
private string _testSymbolsAsString;
private Parser _testParser;
private CommandLineConfiguration _testConfiguration;

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

[Benchmark]
public Parser ParserFromOptions_Ctor()
public CommandLineConfiguration ParserFromOptions_Ctor()
{
return _testSymbols.CreateParser();
return _testSymbols.CreateConfiguration();
}

[GlobalSetup(Target = nameof(ParserFromOptions_Parse))]
public void SetupParserFromOptions_Parse()
{
var testSymbolsArr = GenerateTestOptions(TestSymbolsCount, ArgumentArity.Zero).ToArray();
_testParser = testSymbolsArr.CreateParser();
_testConfiguration = testSymbolsArr.CreateConfiguration();
_testSymbolsAsString = GenerateTestOptionsAsStringExpr(testSymbolsArr.Length);
}

[Benchmark]
public ParseResult ParserFromOptions_Parse() => _testParser.Parse(_testSymbolsAsString);
public ParseResult ParserFromOptions_Parse() => _testConfiguration.RootCommand.Parse(_testSymbolsAsString, _testConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace System.CommandLine.Benchmarks.CommandLine
public class Perf_Parser_Options_With_Arguments
{
private string _testSymbolsAsString;
private Parser _testParser;
private CommandLineConfiguration _configuration;

private IEnumerable<Option> GenerateTestOptions(int count, ArgumentArity arity)
=> Enumerable.Range(0, count)
Expand Down Expand Up @@ -54,11 +54,11 @@ private string GenerateTestOptionsWithArgumentsAsStringExpr(int optionsCount, in
public void SetupParserFromOptionsWithArguments_Parse()
{
var testSymbolsArr = GenerateTestOptions(TestOptionsCount, ArgumentArity.OneOrMore).ToArray();
_testParser = testSymbolsArr.CreateParser();
_configuration = testSymbolsArr.CreateConfiguration();
_testSymbolsAsString = GenerateTestOptionsWithArgumentsAsStringExpr(testSymbolsArr.Length, TestArgumentsCount);
}

[Benchmark]
public ParseResult ParserFromOptionsWithArguments_Parse() => _testParser.Parse(_testSymbolsAsString);
public ParseResult ParserFromOptionsWithArguments_Parse() => _configuration.RootCommand.Parse(_testSymbolsAsString, _configuration);
}
}
Loading