From 403234a4c4247151d09073bc07ccc13530ce62c6 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 31 Mar 2023 04:31:26 -0700 Subject: [PATCH] rename symbol types with Cli prefix; some property renames and file moves (#2132) --- samples/HostingPlayground/Program.cs | 6 +- src/Common/ArgumentBuilder.cs | 14 +- src/Common/OptionBuilder.cs | 14 +- ...ne_Hosting_api_is_not_changed.approved.txt | 4 +- ...tionBinder_api_is_not_changed.approved.txt | 8 +- ...ommandLine_api_is_not_changed.approved.txt | 221 ++++----- .../LocalizationTests.cs | 4 +- .../Perf_Parser_CustomScenarios.cs | 8 +- .../Perf_Parser_Directives_Suggest.cs | 9 +- .../CommandLine/Perf_Parser_NestedCommands.cs | 10 +- .../CommandLine/Perf_Parser_Options_Bare.cs | 6 +- .../Perf_Parser_Options_With_Arguments.cs | 4 +- .../CommandLine/Perf_Parser_ParseResult.cs | 7 +- .../CommandLine/Perf_Parser_Simple.cs | 10 +- .../CommandLine/Perf_Parser_TypoCorrection.cs | 4 +- .../CommandLine/Perf_Suggestions.cs | 10 +- .../Helpers/Utils.cs | 4 +- .../ConfigureFromMethodTests.cs | 28 +- .../CommandLine.cs | 10 +- .../CommandExtensions.cs | 6 +- .../GeneratedCommandHandlerTests.cs | 64 +-- .../CommandHandlerSourceGenerator.cs | 2 +- .../SyntaxReceiver.cs | 6 +- .../HostingHandlerTest.cs | 16 +- .../HostingTests.cs | 20 +- .../DirectiveConfigurationExtensions.cs | 2 +- .../HostingAction.cs | 6 +- .../HostingExtensions.cs | 4 +- .../ModelBinderTests.cs | 150 +++--- ...indingCommandHandlerTests.BindingByName.cs | 12 +- .../ModelBindingCommandHandlerTests.cs | 16 +- .../ParameterBindingTests.cs | 90 ++-- .../BindingContext.cs | 4 +- .../CommandResultExtensions.cs | 4 +- .../ModelBinder.cs | 2 +- .../ModelBinder{T}.cs | 2 +- .../ModelBindingCommandHandler.cs | 8 +- .../SpecificSymbolValueSource.cs | 8 +- .../TableRenderingTests.cs | 20 +- .../ViewRenderingTests.cs | 2 +- .../EndToEndTestApp/Program.cs | 10 +- .../SuggestionDispatcherTests.cs | 2 +- .../SuggestionDispatcher.cs | 35 +- src/System.CommandLine.Tests/ArgumentTests.cs | 150 +++--- .../Binding/TypeConversionTests.cs | 198 ++++---- .../CommandLineConfigurationTests.cs | 70 +-- src/System.CommandLine.Tests/CommandTests.cs | 52 +- .../CompilationTests.cs | 2 +- .../CompletionContextTests.cs | 68 +-- .../CompletionTests.cs | 304 ++++++------ .../DirectiveTests.cs | 44 +- .../EnvironmentVariableDirectiveTests.cs | 14 +- .../GetValueByNameParserTests.cs | 88 ++-- .../GetValueByNameTypeConversionTests.cs | 8 +- .../GlobalOptionTests.cs | 48 +- .../Help/HelpBuilderExtensions.cs | 2 +- .../Help/HelpBuilderTests.Approval.cs | 32 +- .../Help/HelpBuilderTests.Customization.cs | 74 +-- .../Help/HelpBuilderTests.cs | 414 ++++++++-------- .../HelpOptionTests.cs | 38 +- .../CancelOnProcessTerminationTests.cs | 4 +- .../Invocation/InvocationTests.cs | 26 +- .../Invocation/TypoCorrectionTests.cs | 50 +- .../OptionTests.MultipleArgumentsPerToken.cs | 40 +- src/System.CommandLine.Tests/OptionTests.cs | 90 ++-- .../ParseDiagramTests.cs | 46 +- .../ParseDirectiveTests.cs | 45 +- .../ParseResultTests.cs | 42 +- .../ParserTests.DoubleDash.cs | 22 +- .../ParserTests.MultipleArguments.cs | 76 +-- .../ParserTests.MultiplePositions.cs | 46 +- .../ParserTests.RootCommandAndArg0.cs | 40 +- src/System.CommandLine.Tests/ParserTests.cs | 458 +++++++++--------- .../ParsingValidationTests.cs | 266 +++++----- .../ResponseFileTests.cs | 96 ++-- .../RootCommandTests.cs | 4 +- .../SuggestDirectiveTests.cs | 47 +- .../TestApps/NativeAOT/Program.cs | 6 +- .../TestApps/Trimming/Program.cs | 4 +- .../TokenReplacementTests.cs | 36 +- .../UseExceptionHandlerTests.cs | 8 +- .../UseParseErrorReportingTests.cs | 8 +- .../Utility/ParseResultExtensions.cs | 2 +- .../VersionOptionTests.cs | 30 +- src/System.CommandLine/AliasSet.cs | 4 +- src/System.CommandLine/ArgumentArity.cs | 12 +- src/System.CommandLine/ArgumentValidation.cs | 10 +- src/System.CommandLine/Argument{T}.cs | 6 +- .../Binding/ArgumentConverter.cs | 2 +- .../{ChildList.cs => ChildSymbolList{T}.cs} | 6 +- .../{Argument.cs => CliArgument.cs} | 10 +- .../{Command.cs => CliCommand.cs} | 42 +- .../{Directive.cs => CliDirective.cs} | 4 +- .../{Option.cs => CliOption.cs} | 27 +- .../{RootCommand.cs => CliRootCommand.cs} | 6 +- .../{Symbol.cs => CliSymbol.cs} | 10 +- .../CommandLineConfiguration.cs | 17 +- .../{ => Completions}/SuggestDirective.cs | 4 +- .../EnvironmentVariablesDirective.cs | 2 +- .../Help/HelpBuilder.Default.cs | 36 +- src/System.CommandLine/Help/HelpBuilder.cs | 54 +-- .../Help/HelpBuilderExtensions.cs | 4 +- src/System.CommandLine/Help/HelpContext.cs | 4 +- src/System.CommandLine/Help/HelpOption.cs | 12 +- ...rorResult.cs => ParseErrorResultAction.cs} | 0 ...oCorrection.cs => TypoCorrectionAction.cs} | 6 +- src/System.CommandLine/OptionValidation.cs | 10 +- src/System.CommandLine/Option{T}.cs | 23 +- src/System.CommandLine/ParentNode.cs | 4 +- ...eDirective.cs => ParseDiagramDirective.cs} | 22 +- src/System.CommandLine/ParseResult.cs | 26 +- .../Parsing/ArgumentResult.cs | 14 +- .../Parsing/CommandResult.cs | 13 +- .../Parsing/DirectiveResult.cs | 4 +- .../Parsing/OptionResult.cs | 10 +- ...rectiveAction.cs => ParseDiagramAction.cs} | 16 +- .../Parsing/ParseOperation.cs | 10 +- src/System.CommandLine/Parsing/Parser.cs | 6 +- .../Parsing/StringExtensions.cs | 48 +- .../Parsing/SymbolResult.cs | 20 +- .../Parsing/SymbolResultTree.cs | 12 +- src/System.CommandLine/Parsing/Token.cs | 8 +- src/System.CommandLine/Parsing/TokenType.cs | 8 +- src/System.CommandLine/SymbolExtensions.cs | 8 +- .../{Help => }/VersionOption.cs | 20 +- 125 files changed, 2271 insertions(+), 2259 deletions(-) rename src/System.CommandLine/{ChildList.cs => ChildSymbolList{T}.cs} (90%) rename src/System.CommandLine/{Argument.cs => CliArgument.cs} (92%) rename src/System.CommandLine/{Command.cs => CliCommand.cs} (90%) rename src/System.CommandLine/{Directive.cs => CliDirective.cs} (94%) rename src/System.CommandLine/{Option.cs => CliOption.cs} (84%) rename src/System.CommandLine/{RootCommand.cs => CliRootCommand.cs} (90%) rename src/System.CommandLine/{Symbol.cs => CliSymbol.cs} (92%) rename src/System.CommandLine/{ => Completions}/SuggestDirective.cs (96%) rename src/System.CommandLine/Invocation/{ParseErrorResult.cs => ParseErrorResultAction.cs} (100%) rename src/System.CommandLine/Invocation/{TypoCorrection.cs => TypoCorrectionAction.cs} (95%) rename src/System.CommandLine/{ParseDirective.cs => ParseDiagramDirective.cs} (50%) rename src/System.CommandLine/Parsing/{ParseDirectiveAction.cs => ParseDiagramAction.cs} (92%) rename src/System.CommandLine/{Help => }/VersionOption.cs (70%) diff --git a/samples/HostingPlayground/Program.cs b/samples/HostingPlayground/Program.cs index 3f91ffec37..cd05f33386 100644 --- a/samples/HostingPlayground/Program.cs +++ b/samples/HostingPlayground/Program.cs @@ -24,9 +24,9 @@ static Task Main(string[] args) => BuildCommandLine() private static CommandLineConfiguration BuildCommandLine() { - var root = new RootCommand(@"$ dotnet run --name 'Joe'"){ - new Option("--name"){ - IsRequired = true + var root = new CliRootCommand(@"$ dotnet run --name 'Joe'"){ + new CliOption("--name"){ + Required = true } }; root.Action = CommandHandler.Create(Run); diff --git a/src/Common/ArgumentBuilder.cs b/src/Common/ArgumentBuilder.cs index 5c24853f32..5d707e91ad 100644 --- a/src/Common/ArgumentBuilder.cs +++ b/src/Common/ArgumentBuilder.cs @@ -9,12 +9,12 @@ internal static class ArgumentBuilder static ArgumentBuilder() { - _ctor = typeof(Argument).GetConstructor(new[] { typeof(string) }); + _ctor = typeof(CliArgument).GetConstructor(new[] { typeof(string) }); } - public static Argument CreateArgument(Type valueType, string name = "value") + public static CliArgument CreateArgument(Type valueType, string name = "value") { - var argumentType = typeof(Argument<>).MakeGenericType(valueType); + var argumentType = typeof(CliArgument<>).MakeGenericType(valueType); #if NET6_0_OR_GREATER var ctor = (ConstructorInfo)argumentType.GetMemberWithSameMetadataDefinitionAs(_ctor); @@ -22,10 +22,10 @@ public static Argument CreateArgument(Type valueType, string name = "value") var ctor = argumentType.GetConstructor(new[] { typeof(string) }); #endif - return (Argument)ctor.Invoke(new object[] { name }); + return (CliArgument)ctor.Invoke(new object[] { name }); } - internal static Argument CreateArgument(ParameterInfo argsParam) + internal static CliArgument CreateArgument(ParameterInfo argsParam) { if (!argsParam.HasDefaultValue) { @@ -36,10 +36,10 @@ internal static Argument CreateArgument(ParameterInfo argsParam) var ctor = argumentType.GetConstructor(new[] { typeof(string), argsParam.ParameterType }); - return (Argument)ctor.Invoke(new object[] { argsParam.Name, argsParam.DefaultValue }); + return (CliArgument)ctor.Invoke(new object[] { argsParam.Name, argsParam.DefaultValue }); } - private sealed class Bridge : Argument + private sealed class Bridge : CliArgument { public Bridge(string name, T defaultValue) : base(name) diff --git a/src/Common/OptionBuilder.cs b/src/Common/OptionBuilder.cs index fa9ca5d232..768b3eddec 100644 --- a/src/Common/OptionBuilder.cs +++ b/src/Common/OptionBuilder.cs @@ -11,12 +11,12 @@ internal static class OptionBuilder static OptionBuilder() { - _ctor = typeof(Option).GetConstructor(new[] { typeof(string), typeof(string[]) }); + _ctor = typeof(CliOption).GetConstructor(new[] { typeof(string), typeof(string[]) }); } - internal static Option CreateOption(string name, Type valueType, string description = null) + internal static CliOption CreateOption(string name, Type valueType, string description = null) { - var optionType = typeof(Option<>).MakeGenericType(valueType); + var optionType = typeof(CliOption<>).MakeGenericType(valueType); #if NET6_0_OR_GREATER var ctor = (ConstructorInfo)optionType.GetMemberWithSameMetadataDefinitionAs(_ctor); @@ -24,14 +24,14 @@ internal static Option CreateOption(string name, Type valueType, string descript var ctor = optionType.GetConstructor(new[] { typeof(string), typeof(string[]) }); #endif - var option = (Option)ctor.Invoke(new object[] { name, Array.Empty() }); + var option = (CliOption)ctor.Invoke(new object[] { name, Array.Empty() }); option.Description = description; return option; } - internal static Option CreateOption(string name, Type valueType, string description, Func defaultValueFactory) + internal static CliOption CreateOption(string name, Type valueType, string description, Func defaultValueFactory) { if (defaultValueFactory == null) { @@ -42,12 +42,12 @@ internal static Option CreateOption(string name, Type valueType, string descript var ctor = optionType.GetConstructor(new[] { typeof(string), typeof(Func), typeof(string) }); - var option = (Option)ctor.Invoke(new object[] { name, defaultValueFactory, description }); + var option = (CliOption)ctor.Invoke(new object[] { name, defaultValueFactory, description }); return option; } - private sealed class Bridge : Option + private sealed class Bridge : CliOption { 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 d419f8902a..5e9f1af93c 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 @@ -1,12 +1,12 @@ System.CommandLine.Hosting public static class DirectiveConfigurationExtensions - public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLineDirectives(this Microsoft.Extensions.Configuration.IConfigurationBuilder config, System.CommandLine.ParseResult commandline, System.CommandLine.Directive directive) + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLineDirectives(this Microsoft.Extensions.Configuration.IConfigurationBuilder config, System.CommandLine.ParseResult commandline, System.CommandLine.CliDirective directive) public static class HostingExtensions public static OptionsBuilder BindCommandLine(this OptionsBuilder optionsBuilder) 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.Command UseCommandHandler(this System.CommandLine.Command command) + public static System.CommandLine.CliCommand UseCommandHandler(this System.CommandLine.CliCommand command) public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Action configureHost = null) public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Func hostBuilderFactory, System.Action configureHost = null) public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.Action configureOptions = 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 c8ab50bdd7..3b24de558b 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 @@ -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.Symbol symbol) + public System.Void BindMemberFromValue(System.Reflection.PropertyInfo property, System.CommandLine.CliSymbol 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.Symbol symbol) + public System.Void BindMemberFromValue(Expression> property, System.CommandLine.CliSymbol symbol) public System.Void BindMemberFromValue(Expression> property, Func getValue) public class ModelBindingCommandHandler : BindingHandler - 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.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.CliArgument argument) + public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.CliOption option) public System.Int32 Invoke(System.CommandLine.ParseResult parseResult) public System.Threading.Tasks.Task InvokeAsync(System.CommandLine.ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null) public class ModelDescriptor 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 3b31cc7dca..1e546fd4a4 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,5 +1,25 @@ System.CommandLine - public abstract class Argument : Symbol + 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 CliAction + public System.Int32 Invoke(ParseResult parseResult) + public System.Threading.Tasks.Task InvokeAsync(ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null) + public abstract class CliArgument : CliSymbol public ArgumentArity Arity { get; set; } public System.Collections.Generic.List>> CompletionSources { get; } public System.Boolean HasDefaultValue { get; } @@ -9,7 +29,7 @@ System.CommandLine public System.Collections.Generic.IEnumerable GetCompletions(System.CommandLine.Completions.CompletionContext context) public System.Object GetDefaultValue() public System.String ToString() - public class Argument : Argument + public class CliArgument : CliArgument .ctor(System.String name) public Func CustomParser { get; set; } public Func DefaultValueFactory { get; set; } @@ -18,48 +38,63 @@ System.CommandLine public System.Void AcceptLegalFileNamesOnly() public System.Void AcceptLegalFilePathsOnly() public System.Void AcceptOnlyFromAmong(System.String[] values) - 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 abstract class CliAction - public System.Int32 Invoke(ParseResult parseResult) - public System.Threading.Tasks.Task InvokeAsync(ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null) - public class Command : Symbol, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + public class CliCommand : CliSymbol, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable .ctor(System.String name, System.String description = null) public CliAction 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