diff --git a/samples/HostingPlayground/Program.cs b/samples/HostingPlayground/Program.cs index b5f6600d01..4356ecb619 100644 --- a/samples/HostingPlayground/Program.cs +++ b/samples/HostingPlayground/Program.cs @@ -22,15 +22,15 @@ static Task Main(string[] args) => BuildCommandLine() }) .InvokeAsync(args); - private static CliConfiguration BuildCommandLine() + private static CommandLineConfiguration BuildCommandLine() { - var root = new CliRootCommand(@"$ dotnet run --name 'Joe'"){ - new CliOption("--name"){ + var root = new RootCommand(@"$ dotnet run --name 'Joe'"){ + new Option("--name"){ Required = true } }; root.Action = CommandHandler.Create(Run); - return new CliConfiguration(root); + return new CommandLineConfiguration(root); } private static void Run(GreeterOptions options, IHost host) diff --git a/src/Common/ArgumentBuilder.cs b/src/Common/ArgumentBuilder.cs index 5d707e91ad..5c24853f32 100644 --- a/src/Common/ArgumentBuilder.cs +++ b/src/Common/ArgumentBuilder.cs @@ -9,12 +9,12 @@ internal static class ArgumentBuilder static ArgumentBuilder() { - _ctor = typeof(CliArgument).GetConstructor(new[] { typeof(string) }); + _ctor = typeof(Argument).GetConstructor(new[] { typeof(string) }); } - public static CliArgument CreateArgument(Type valueType, string name = "value") + public static Argument CreateArgument(Type valueType, string name = "value") { - var argumentType = typeof(CliArgument<>).MakeGenericType(valueType); + var argumentType = typeof(Argument<>).MakeGenericType(valueType); #if NET6_0_OR_GREATER var ctor = (ConstructorInfo)argumentType.GetMemberWithSameMetadataDefinitionAs(_ctor); @@ -22,10 +22,10 @@ public static CliArgument CreateArgument(Type valueType, string name = "value") var ctor = argumentType.GetConstructor(new[] { typeof(string) }); #endif - return (CliArgument)ctor.Invoke(new object[] { name }); + return (Argument)ctor.Invoke(new object[] { name }); } - internal static CliArgument CreateArgument(ParameterInfo argsParam) + internal static Argument CreateArgument(ParameterInfo argsParam) { if (!argsParam.HasDefaultValue) { @@ -36,10 +36,10 @@ internal static CliArgument CreateArgument(ParameterInfo argsParam) var ctor = argumentType.GetConstructor(new[] { typeof(string), argsParam.ParameterType }); - return (CliArgument)ctor.Invoke(new object[] { argsParam.Name, argsParam.DefaultValue }); + return (Argument)ctor.Invoke(new object[] { argsParam.Name, argsParam.DefaultValue }); } - private sealed class Bridge : CliArgument + private sealed class Bridge : Argument { public Bridge(string name, T defaultValue) : base(name) diff --git a/src/Common/OptionBuilder.cs b/src/Common/OptionBuilder.cs index 768b3eddec..fa9ca5d232 100644 --- a/src/Common/OptionBuilder.cs +++ b/src/Common/OptionBuilder.cs @@ -11,12 +11,12 @@ internal static class OptionBuilder static OptionBuilder() { - _ctor = typeof(CliOption).GetConstructor(new[] { typeof(string), typeof(string[]) }); + _ctor = typeof(Option).GetConstructor(new[] { typeof(string), typeof(string[]) }); } - internal static CliOption CreateOption(string name, Type valueType, string description = null) + internal static Option CreateOption(string name, Type valueType, string description = null) { - var optionType = typeof(CliOption<>).MakeGenericType(valueType); + var optionType = typeof(Option<>).MakeGenericType(valueType); #if NET6_0_OR_GREATER var ctor = (ConstructorInfo)optionType.GetMemberWithSameMetadataDefinitionAs(_ctor); @@ -24,14 +24,14 @@ internal static CliOption CreateOption(string name, Type valueType, string descr var ctor = optionType.GetConstructor(new[] { typeof(string), typeof(string[]) }); #endif - var option = (CliOption)ctor.Invoke(new object[] { name, Array.Empty() }); + var option = (Option)ctor.Invoke(new object[] { name, Array.Empty() }); option.Description = description; return option; } - internal static CliOption CreateOption(string name, Type valueType, string description, Func defaultValueFactory) + internal static Option CreateOption(string name, Type valueType, string description, Func defaultValueFactory) { if (defaultValueFactory == null) { @@ -42,12 +42,12 @@ internal static CliOption CreateOption(string name, Type valueType, string descr var ctor = optionType.GetConstructor(new[] { typeof(string), typeof(Func), typeof(string) }); - var option = (CliOption)ctor.Invoke(new object[] { name, defaultValueFactory, description }); + var option = (Option)ctor.Invoke(new object[] { name, defaultValueFactory, description }); return option; } - private sealed class Bridge : CliOption + private sealed class Bridge : Option { public Bridge(string name, Func defaultValueFactory, string description) : base(name) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_Hosting_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_Hosting_api_is_not_changed.approved.txt index 2cedf6abc6..e09e960373 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_Hosting_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_Hosting_api_is_not_changed.approved.txt @@ -4,9 +4,9 @@ System.CommandLine.Hosting public static Microsoft.Extensions.Hosting.IHost GetHost(this System.CommandLine.ParseResult parseResult) 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(this System.CommandLine.CliCommand command) - public static System.CommandLine.CliConfiguration UseHost(this System.CommandLine.CliConfiguration config, System.Action configureHost = null) - public static System.CommandLine.CliConfiguration UseHost(this System.CommandLine.CliConfiguration config, System.Func hostBuilderFactory, System.Action configureHost = null) + public static System.CommandLine.Command UseCommandHandler(this System.CommandLine.Command command) + public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration config, System.Action configureHost = null) + public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration config, System.Func hostBuilderFactory, System.Action configureHost = null) public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.Action configureOptions = null) public class InvocationLifetime, Microsoft.Extensions.Hosting.IHostLifetime .ctor(Microsoft.Extensions.Options.IOptions options, Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = null) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt index 2a9e067492..722203167a 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt @@ -21,7 +21,7 @@ System.CommandLine.NamingConventionBinder public static System.Void AddModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, ModelBinder binder) public static System.CommandLine.Binding.BindingContext GetBindingContext(this System.CommandLine.ParseResult parseResult) public static ModelBinder GetOrCreateModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, System.CommandLine.Binding.IValueDescriptor valueDescriptor) - public abstract class BindingHandler : System.CommandLine.Invocation.AsynchronousCliAction + public abstract class BindingHandler : System.CommandLine.Invocation.AsynchronousCommandLineAction public System.CommandLine.Binding.BindingContext GetBindingContext(System.CommandLine.ParseResult parseResult) public static class CommandHandler public static BindingHandler Create(System.Delegate delegate) @@ -109,16 +109,16 @@ System.CommandLine.NamingConventionBinder public System.Boolean EnforceExplicitBinding { get; set; } public ModelDescriptor ModelDescriptor { get; } public System.CommandLine.Binding.IValueDescriptor ValueDescriptor { get; } - public System.Void BindMemberFromValue(System.Reflection.PropertyInfo property, System.CommandLine.CliSymbol symbol) + public System.Void BindMemberFromValue(System.Reflection.PropertyInfo property, System.CommandLine.Symbol symbol) public System.Object CreateInstance(System.CommandLine.Binding.BindingContext bindingContext) public System.Void UpdateInstance(T instance, System.CommandLine.Binding.BindingContext bindingContext) public class ModelBinder : ModelBinder .ctor() - public System.Void BindMemberFromValue(Expression> property, System.CommandLine.CliSymbol symbol) + public System.Void BindMemberFromValue(Expression> property, System.CommandLine.Symbol symbol) public System.Void BindMemberFromValue(Expression> property, Func getValue) public class ModelBindingCommandHandler : BindingHandler - public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.CliArgument argument) - public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.CliOption option) + public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Argument argument) + public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Option option) public System.Threading.Tasks.Task InvokeAsync(System.CommandLine.ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null) public class ModelDescriptor public static ModelDescriptor FromType() 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 b2a228caa8..2d12ffc071 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 @@ -1,22 +1,5 @@ System.CommandLine - public struct ArgumentArity : System.ValueType, System.IEquatable - public static ArgumentArity ExactlyOne { get; } - public static ArgumentArity OneOrMore { get; } - public static ArgumentArity Zero { get; } - public static ArgumentArity ZeroOrMore { get; } - public static ArgumentArity ZeroOrOne { get; } - .ctor(System.Int32 minimumNumberOfValues, System.Int32 maximumNumberOfValues) - public System.Int32 MaximumNumberOfValues { get; } - public System.Int32 MinimumNumberOfValues { get; } - public System.Boolean Equals(ArgumentArity other) - public System.Boolean Equals(System.Object obj) - public System.Int32 GetHashCode() - public static class ArgumentValidation - public static CliArgument AcceptExistingOnly(this CliArgument argument) - public static CliArgument AcceptExistingOnly(this CliArgument argument) - public static CliArgument AcceptExistingOnly(this CliArgument argument) - public static CliArgument AcceptExistingOnly(this CliArgument argument) - public abstract class CliArgument : CliSymbol + public abstract class Argument : Symbol public ArgumentArity Arity { get; set; } public System.Collections.Generic.List>> CompletionSources { get; } public System.Boolean HasDefaultValue { get; } @@ -26,7 +9,7 @@ System.CommandLine public System.Collections.Generic.IEnumerable GetCompletions(System.CommandLine.Completions.CompletionContext context) public System.Object GetDefaultValue() public System.String ToString() - public class CliArgument : CliArgument + public class Argument : Argument .ctor(System.String name) public Func CustomParser { get; set; } public Func DefaultValueFactory { get; set; } @@ -35,35 +18,52 @@ System.CommandLine public System.Void AcceptLegalFileNamesOnly() public System.Void AcceptLegalFilePathsOnly() public System.Void AcceptOnlyFromAmong(System.String[] values) - public class CliCommand : CliSymbol, System.Collections.IEnumerable + public struct ArgumentArity : System.ValueType, System.IEquatable + public static ArgumentArity ExactlyOne { get; } + public static ArgumentArity OneOrMore { get; } + public static ArgumentArity Zero { get; } + public static ArgumentArity ZeroOrMore { get; } + public static ArgumentArity ZeroOrOne { get; } + .ctor(System.Int32 minimumNumberOfValues, System.Int32 maximumNumberOfValues) + public System.Int32 MaximumNumberOfValues { get; } + public System.Int32 MinimumNumberOfValues { get; } + public System.Boolean Equals(ArgumentArity other) + public System.Boolean Equals(System.Object obj) + public System.Int32 GetHashCode() + public static class ArgumentValidation + public static Argument AcceptExistingOnly(this Argument argument) + public static Argument AcceptExistingOnly(this Argument argument) + public static Argument AcceptExistingOnly(this Argument argument) + public static Argument AcceptExistingOnly(this Argument argument) + public class Command : Symbol, System.Collections.IEnumerable .ctor(System.String name, System.String description = null) - public System.CommandLine.Invocation.CliAction Action { get; set; } + public System.CommandLine.Invocation.CommandLineAction Action { get; set; } public System.Collections.Generic.ICollection Aliases { get; } - public System.Collections.Generic.IList Arguments { get; } - public System.Collections.Generic.IEnumerable Children { get; } - public System.Collections.Generic.IList Options { get; } - public System.Collections.Generic.IList Subcommands { get; } + public System.Collections.Generic.IList Arguments { get; } + public System.Collections.Generic.IEnumerable Children { get; } + public System.Collections.Generic.IList