From 95d879fc497c77479eb0f6abc064e8b69cef51fd Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Wed, 12 Nov 2025 17:17:51 -0800 Subject: [PATCH 1/4] Template Engine CLI commands: separate definitions from implementations --- .../CollectionExtensions.cs | 15 + .../CommandDefinitions/CommandDefinition.cs | 505 ++++++++++++++++++ .../CommandDefinitionExtensions.cs | 119 +++++ .../FilterOptionDefinition.cs | 0 .../Commands/BaseCommand.cs | 80 ++- .../Commands/GlobalArgs.cs | 12 +- .../Commands/NewCommand.Legacy.cs | 168 ------ .../Commands/NewCommand.cs | 97 +--- .../Commands/NewCommandArgs.cs | 2 +- .../Commands/SharedOptions.cs | 6 + .../Commands/alias/AliasAddCommand.cs | 14 +- .../Commands/alias/AliasCommand.cs | 12 +- .../Commands/alias/AliasShowCommand.cs | 14 +- .../Commands/alias/BaseAliasAddCommand.cs | 8 +- .../Commands/alias/BaseAliasShowCommand.cs | 8 +- .../Commands/alias/LegacyAliasAddCommand.cs | 15 +- .../Commands/alias/LegacyAliasShowCommand.cs | 14 +- .../create/InstantiateCommand.Help.cs | 4 +- .../InstantiateCommand.NoMatchHandling.cs | 2 +- .../Commands/create/InstantiateCommand.cs | 43 +- .../Commands/create/InstantiateCommandArgs.cs | 4 +- .../Commands/details/DetailsCommand.cs | 29 +- .../Commands/details/DetailsCommandArgs.cs | 8 +- .../Commands/install/BaseInstallCommand.cs | 34 +- .../Commands/install/InstallCommand.cs | 11 +- .../Commands/install/InstallCommandArgs.cs | 14 +- .../Commands/install/LegacyInstallCommand.cs | 16 +- .../Commands/list/BaseListCommand.cs | 48 +- .../Commands/list/LegacyListCommand.cs | 36 +- .../Commands/list/ListCommand.cs | 11 +- .../Commands/list/ListCommandArgs.cs | 9 +- .../Commands/search/BaseSearchCommand.cs | 43 +- .../Commands/search/LegacySearchCommand.cs | 33 +- .../Commands/search/SearchCommand.cs | 11 +- .../Commands/search/SearchCommandArgs.cs | 6 +- .../uninstall/BaseUninstallCommand.cs | 17 +- .../uninstall/LegacyUninstallCommand.cs | 14 +- .../Commands/uninstall/UninstallCommand.cs | 11 +- .../uninstall/UninstallCommandArgs.cs | 2 +- .../Commands/update/BaseUpdateCommand.cs | 21 +- .../update/LegacyUpdateApplyCommand.cs | 16 +- .../update/LegacyUpdateCheckCommand.cs | 18 +- .../Commands/update/UpdateCommand.cs | 18 +- .../Commands/update/UpdateCommandArgs.cs | 8 +- .../Microsoft.TemplateEngine.Cli.csproj | 1 - .../NewCommandFactory.cs | 13 +- .../TemplateInvoker.cs | 8 +- .../TemplateListCoordinator.cs | 14 +- .../TemplatePackageCoordinator.cs | 20 +- .../TemplatePackageDisplay.cs | 20 +- .../TemplateMatchInfoExtensions.cs | 2 +- .../CliTemplateSearchCoordinator.cs | 10 +- .../dotnet/Commands/New/NewCommandParser.cs | 2 +- .../AliasAssignmentTests.cs | 4 +- .../ParserTests/HelpTests.Resolution.cs | 26 +- .../ParserTests/HelpTests.cs | 34 +- .../ParserTests/InstallTests.cs | 28 +- .../InstantiateTests.NoMatchHandling.cs | 2 +- .../InstantiateTests.Subcommand.cs | 18 +- .../ParserTests/InstantiateTests.cs | 32 +- .../ParserTests/ListTests.cs | 22 +- .../ParserTests/MiscTests.cs | 12 +- .../ParserTests/SearchTests.cs | 32 +- .../TabCompletionTests.Approval.cs | 20 +- .../ParserTests/TabCompletionTests.cs | 44 +- .../ParserTests/TemplateCommandTests.cs | 2 +- .../ParserTests/UninstallTests.cs | 12 +- .../ParserTests/UpdateTests.cs | 22 +- .../TemplatePackageDisplayTest.cs | 6 +- .../ListTemplateResolverTests.cs | 6 +- .../TemplateSearchCoordinatorTests.cs | 20 +- 71 files changed, 1014 insertions(+), 994 deletions(-) create mode 100644 src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CollectionExtensions.cs create mode 100644 src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CommandDefinition.cs create mode 100644 src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CommandDefinitionExtensions.cs rename src/Cli/Microsoft.TemplateEngine.Cli/{Commands => CommandDefinitions}/FilterOptionDefinition.cs (100%) delete mode 100644 src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.Legacy.cs diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CollectionExtensions.cs b/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CollectionExtensions.cs new file mode 100644 index 000000000000..e6fdd134c22d --- /dev/null +++ b/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CollectionExtensions.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.TemplateEngine.Cli; + +internal static class CollectionExtensions +{ + public static void AddRange(this ICollection collection, IEnumerable items) + { + foreach (T item in items) + { + collection.Add(item); + } + } +} diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CommandDefinition.cs b/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CommandDefinition.cs new file mode 100644 index 000000000000..333eb9364256 --- /dev/null +++ b/src/Cli/Microsoft.TemplateEngine.Cli/CommandDefinitions/CommandDefinition.cs @@ -0,0 +1,505 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma warning disable CA1810 // Initialize reference type static fields inline + +using System.CommandLine; +using Microsoft.TemplateEngine.Cli.Commands; + +namespace Microsoft.TemplateEngine.Cli; + +internal class CommandDefinition(string name, string description) : Command(name, description) +{ + public static class New + { + public static readonly Option DebugCustomSettingsLocationOption = new("--debug:custom-hive") + { + Description = SymbolStrings.Option_Debug_CustomSettings, + Hidden = true, + Recursive = true + }; + + public static readonly Option DebugVirtualizeSettingsOption = new("--debug:ephemeral-hive", "--debug:virtual-hive") + { + Description = SymbolStrings.Option_Debug_VirtualSettings, + Hidden = true, + Recursive = true + }; + + public static readonly Option DebugAttachOption = new("--debug:attach") + { + Description = SymbolStrings.Option_Debug_Attach, + Hidden = true, + Recursive = true + }; + + public static readonly Option DebugReinitOption = new("--debug:reinit") + { + Description = SymbolStrings.Option_Debug_Reinit, + Hidden = true, + Recursive = true + }; + + public static readonly Option DebugRebuildCacheOption = new("--debug:rebuild-cache", "--debug:rebuildcache") + { + Description = SymbolStrings.Option_Debug_RebuildCache, + Hidden = true, + Recursive = true + }; + + public static readonly Option DebugShowConfigOption = new("--debug:show-config", "--debug:showconfig") + { + Description = SymbolStrings.Option_Debug_ShowConfig, + Hidden = true, + Recursive = true + }; + + public static readonly Argument ShortNameArgument = new("template-short-name") + { + Description = SymbolStrings.Command_Instantiate_Argument_ShortName, + Arity = new ArgumentArity(0, 1), + Hidden = true + }; + + public static readonly Argument RemainingArguments = new("template-args") + { + Description = SymbolStrings.Command_Instantiate_Argument_TemplateOptions, + Arity = new ArgumentArity(0, 999), + Hidden = true + }; + + public static readonly Option InteractiveOption = SharedOptionsFactory.CreateInteractiveOption().AsHidden(); + + public static readonly Option AddSourceOption = SharedOptionsFactory.CreateAddSourceOption().AsHidden().DisableAllowMultipleArgumentsPerToken(); + + public static readonly Option ColumnsAllOption = SharedOptionsFactory.CreateColumnsAllOption().AsHidden(); + + public static readonly Option ColumnsOption = SharedOptionsFactory.CreateColumnsOption().AsHidden().DisableAllowMultipleArgumentsPerToken(); + + public static IReadOnlyList