diff --git a/Directory.Packages.props b/Directory.Packages.props index da1e624248..cf42c3fd4d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,12 +9,12 @@ - + - + diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index f19908599f..d9c2d7f7d8 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -104,6 +104,14 @@ public static Option AcceptExistingOnly(this Option option) public static Option AcceptExistingOnly(this Option option) public static Option AcceptExistingOnly(this Option option) + public class ParsableArgument : Argument + .ctor(System.String name) + public class ParsableListArgument : Argument> + .ctor(System.String name) + public class ParsableListOption : Option> + .ctor(System.String name, System.String[] aliases) + public class ParsableOption : Option + .ctor(System.String name, System.String[] aliases) public class ParserConfiguration .ctor() public System.Boolean EnablePosixBundling { get; set; } @@ -140,6 +148,10 @@ .ctor(System.String description = ) public System.Collections.Generic.IList Directives { get; } public System.Void Add(Directive directive) + public class SpanParsableArgument : Argument + .ctor(System.String name) + public class SpanParsableOption : Option + .ctor(System.String name, System.String[] aliases) public abstract class Symbol public System.String Description { get; set; } public System.Boolean Hidden { get; set; } diff --git a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_CustomScenarios.cs b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_CustomScenarios.cs index 0aa02b9eb9..37030de962 100644 --- a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_CustomScenarios.cs +++ b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_CustomScenarios.cs @@ -13,24 +13,22 @@ namespace System.CommandLine.Benchmarks.CommandLine public class Perf_Parser_CustomScenarios { private string _testSymbolsAsString; - private CliCommand _rootCommand; - private CliConfiguration _configuration; - + private Command _rootCommand; + [GlobalSetup(Target = nameof(OneOptWithNestedCommand_Parse))] public void SetupOneOptWithNestedCommand() { - _rootCommand = new CliCommand("root_command"); - var nestedCommand = new CliCommand("nested_command"); - var option = new CliOption("-opt1") { DefaultValueFactory = (_) => 123 }; + _rootCommand = new Command("root_command"); + var nestedCommand = new Command("nested_command"); + var option = new Option("-opt1") { DefaultValueFactory = (_) => 123 }; nestedCommand.Options.Add(option); _rootCommand.Subcommands.Add(nestedCommand); _testSymbolsAsString = "root_command nested_command -opt1 321"; - _configuration = new CliConfiguration(_rootCommand); } [Benchmark] public ParseResult OneOptWithNestedCommand_Parse() - => _rootCommand.Parse(_testSymbolsAsString, _configuration); + => _rootCommand.Parse(_testSymbolsAsString); } } diff --git a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Directives_Suggest.cs b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Directives_Suggest.cs index bec7003a94..a68a74dab3 100644 --- a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Directives_Suggest.cs +++ b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Directives_Suggest.cs @@ -13,28 +13,22 @@ namespace System.CommandLine.Benchmarks.CommandLine [BenchmarkCategory(Categories.CommandLine)] public class Perf_Parser_Directives_Suggest { - private CliConfiguration _configuration; + public Command eatCommand; [GlobalSetup] public void Setup() { - CliOption fruitOption = new("--fruit"); + Option fruitOption = new("--fruit"); fruitOption.CompletionSources.Add("apple", "banana", "cherry"); - CliOption vegetableOption = new("--vegetable"); + Option vegetableOption = new("--vegetable"); vegetableOption.CompletionSources.Add("asparagus", "broccoli", "carrot"); - var eatCommand = new CliCommand("eat") + eatCommand = new Command("eat") { fruitOption, vegetableOption }; - - _configuration = new CliConfiguration(eatCommand) - { - Directives = { new SuggestDirective() }, - Output = System.IO.TextWriter.Null - }; } [Params( @@ -45,7 +39,7 @@ public void Setup() [Benchmark] public Task InvokeSuggest() - => _configuration.InvokeAsync(TestCmdArgs); + => eatCommand.Parse(TestCmdArgs).InvokeAsync(); } } diff --git a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs index 2faae64a67..d9f4702cab 100644 --- a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs +++ b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs @@ -13,8 +13,7 @@ namespace System.CommandLine.Benchmarks.CommandLine public class Perf_Parser_NestedCommands { private string _testSymbolsAsString; - private CliCommand _rootCommand; - private CliConfiguration _configuration; + private Command _rootCommand; /// /// 1 - cmd-root @@ -31,7 +30,7 @@ public class Perf_Parser_NestedCommands [Params(1, 2, 5)] public int TestCommandsDepth; - private void GenerateTestNestedCommands(CliCommand parent, int depth, int countPerLevel) + private void GenerateTestNestedCommands(Command parent, int depth, int countPerLevel) { if (depth == 0) return; @@ -39,7 +38,7 @@ private void GenerateTestNestedCommands(CliCommand parent, int depth, int countP for (int i = 0; i < countPerLevel; i++) { string cmdName = $"{parent.Name}_{depth}.{i}"; - CliCommand cmd = new(cmdName); + Command cmd = new(cmdName); parent.Subcommands.Add(cmd); GenerateTestNestedCommands(cmd, depth - 1, countPerLevel); } @@ -49,12 +48,12 @@ private void GenerateTestNestedCommands(CliCommand parent, int depth, int countP public void SetupRootCommand() { string rootCommandName = "root"; - var rootCommand = new CliCommand(rootCommandName); + var rootCommand = new Command(rootCommandName); _testSymbolsAsString = rootCommandName; GenerateTestNestedCommands(rootCommand, TestCommandsDepth, TestCommandsDepth); // Choose only one path from the commands tree for the test arguments string - CliCommand currentCmd = rootCommand; + Command currentCmd = rootCommand; while (currentCmd is not null && currentCmd.Subcommands.Count > 0) { currentCmd = currentCmd.Subcommands[0]; @@ -62,10 +61,9 @@ public void SetupRootCommand() } _rootCommand = rootCommand; - _configuration = new CliConfiguration(rootCommand); } [Benchmark] - public ParseResult Parser_Parse() => CliParser.Parse(_rootCommand, _testSymbolsAsString, _configuration); + public ParseResult Parser_Parse() => _rootCommand.Parse(_testSymbolsAsString); } } diff --git a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Options_Bare.cs b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Options_Bare.cs index 12e241b92b..2bd06c4550 100644 --- a/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Options_Bare.cs +++ b/src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Options_Bare.cs @@ -15,14 +15,14 @@ namespace System.CommandLine.Benchmarks.CommandLine [BenchmarkCategory(Categories.CommandLine)] public class Perf_Parser_Options_Bare { - private IEnumerable _testSymbols; + private IEnumerable