diff --git a/src/Microsoft.TemplateEngine.Cli/AppExtensions.cs b/src/Microsoft.TemplateEngine.Cli/AppExtensions.cs deleted file mode 100644 index 3a4cc48742e..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/AppExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Microsoft.TemplateEngine.Cli -{ - internal static class AppExtensions - { - internal static IReadOnlyList CreateArgListFromAdditionalFiles(IReadOnlyList extraArgFileNames) - { - IReadOnlyDictionary> argsDict = ParseArgsFromFile(extraArgFileNames); - - List argsFlattened = new List(); - foreach (KeyValuePair> oneArg in argsDict) - { - argsFlattened.Add(oneArg.Key); - if (oneArg.Value.Count > 0) - { - argsFlattened.AddRange(oneArg.Value); - } - } - - return argsFlattened; - } - - internal static IReadOnlyDictionary> ParseArgsFromFile(IReadOnlyList extraArgFileNames) - { - Dictionary> parameters = new Dictionary>(); - - // Note: If the same param is specified multiple times across the files, last-in-wins - // TODO: consider another course of action. - if (extraArgFileNames.Count > 0) - { - foreach (string argFile in extraArgFileNames) - { - if (!File.Exists(argFile)) - { - throw new CommandParserException(string.Format(LocalizableStrings.ArgsFileNotFound, argFile), argFile); - } - - try - { - using (Stream s = File.OpenRead(argFile)) - using (TextReader r = new StreamReader(s, Encoding.UTF8, true, 4096, true)) - using (JsonTextReader reader = new JsonTextReader(r)) - { - JObject obj = JObject.Load(reader); - - foreach (JProperty property in obj.Properties()) - { - if (property.Value.Type == JTokenType.String) - { - IReadOnlyList values = new List - { - property.Value.ToString() - }; - - // adding 2 dashes to the file-based params - // won't work right if there's a param that should have 1 dash - // - // TOOD: come up with a better way to deal with this - parameters["--" + property.Name] = values; - } - } - } - } - catch (Exception ex) - { - throw new CommandParserException(string.Format(LocalizableStrings.ArgsFileWrongFormat, argFile), argFile, ex); - } - } - } - - return parameters; - } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/CommandParserException.cs b/src/Microsoft.TemplateEngine.Cli/CommandParserException.cs deleted file mode 100644 index 7caa5fc28cf..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/CommandParserException.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -namespace Microsoft.TemplateEngine.Cli -{ - public class CommandParserException : Exception - { - internal CommandParserException(string message, string argument) - : base(message) - { - Argument = argument; - } - - internal CommandParserException(string message, string argument, Exception innerException) - : base(message, innerException) - { - Argument = argument; - } - - public string Argument { get; } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs index d97330b55b8..60639de334e 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs @@ -10,6 +10,7 @@ using System.Reflection; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Abstractions.Mount; +using Microsoft.TemplateEngine.Cli.TabularOutput; using Microsoft.TemplateEngine.Edge; using Microsoft.TemplateEngine.Edge.Settings; using Microsoft.TemplateEngine.Utils; @@ -271,19 +272,27 @@ private static void HandleDebugShowConfig(TArgs args, IEngineEnvironmentSettings Reporter.Output.WriteLine(LocalizableStrings.CurrentConfiguration); Reporter.Output.WriteLine(" "); - TableFormatter.Print(environmentSettings.Components.OfType(), LocalizableStrings.NoItems, " ", '-', new Dictionary> - { - { LocalizableStrings.MountPointFactories, x => x.Id }, - { LocalizableStrings.Type, x => x.GetType().FullName ?? string.Empty }, - { LocalizableStrings.Assembly, x => x.GetType().GetTypeInfo().Assembly.FullName ?? string.Empty } - }); - - TableFormatter.Print(environmentSettings.Components.OfType(), LocalizableStrings.NoItems, " ", '-', new Dictionary> - { - { LocalizableStrings.Generators, x => x.Id }, - { LocalizableStrings.Type, x => x.GetType().FullName ?? string.Empty }, - { LocalizableStrings.Assembly, x => x.GetType().GetTypeInfo().Assembly.FullName ?? string.Empty } - }); + TabularOutput mountPointsFormatter = + TabularOutput.TabularOutput + .For( + new TabularOutputSettings(environmentSettings.Environment), + environmentSettings.Components.OfType()) + .DefineColumn(mp => mp.Id.ToString(), LocalizableStrings.MountPointFactories, showAlways: true) + .DefineColumn(mp => mp.GetType().FullName ?? string.Empty, LocalizableStrings.Type, showAlways: true) + .DefineColumn(mp => mp.GetType().GetTypeInfo().Assembly.FullName ?? string.Empty, LocalizableStrings.Assembly, showAlways: true); + Reporter.Output.WriteLine(mountPointsFormatter.Layout()); + Reporter.Output.WriteLine(); + + TabularOutput generatorsFormatter = + TabularOutput.TabularOutput + .For( + new TabularOutputSettings(environmentSettings.Environment), + environmentSettings.Components.OfType()) + .DefineColumn(g => g.Id.ToString(), LocalizableStrings.Generators, showAlways: true) + .DefineColumn(g => g.GetType().FullName ?? string.Empty, LocalizableStrings.Type, showAlways: true) + .DefineColumn(g => g.GetType().GetTypeInfo().Assembly.FullName ?? string.Empty, LocalizableStrings.Assembly, showAlways: true); + Reporter.Output.WriteLine(generatorsFormatter.Layout()); + Reporter.Output.WriteLine(); } } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/InstallCommand.cs deleted file mode 100644 index 8edf77cbb7b..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/Commands/InstallCommand.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -using System.CommandLine; -using System.CommandLine.Invocation; -using System.CommandLine.Parsing; -using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Edge.Settings; - -namespace Microsoft.TemplateEngine.Cli.Commands -{ - internal class InstallCommand : BaseInstallCommand - { - public InstallCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "install") - { - parentCommand.AddNoLegacyUsageValidators(this); - } - } - - internal class LegacyInstallCommand : BaseInstallCommand - { - public LegacyInstallCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "--install") - { - this.IsHidden = true; - this.AddAlias("-i"); - - parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); - } - - internal override Option InteractiveOption => ParentCommand.InteractiveOption; - - internal override Option> AddSourceOption => ParentCommand.AddSourceOption; - } - - internal abstract class BaseInstallCommand : BaseCommand - { - internal BaseInstallCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks, - string commandName) - : base(host, logger, callbacks, commandName, SymbolStrings.Command_Install_Description) - { - ParentCommand = parentCommand; - this.AddArgument(NameArgument); - this.AddOption(InteractiveOption); - this.AddOption(AddSourceOption); - } - - internal Argument> NameArgument { get; } = new("package") - { - Description = SymbolStrings.Command_Install_Argument_Package, - Arity = new ArgumentArity(1, 99) - }; - - internal virtual Option InteractiveOption { get; } = SharedOptionsFactory.CreateInteractiveOption(); - - internal virtual Option> AddSourceOption { get; } = SharedOptionsFactory.CreateAddSourceOption(); - - protected NewCommand ParentCommand { get; } - - protected override async Task ExecuteAsync(InstallCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) - { - using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); - TemplatePackageCoordinator templatePackageCoordinator = new TemplatePackageCoordinator( - TelemetryLogger, - environmentSettings, - templatePackageManager); - - //we need to await, otherwise templatePackageManager will be disposed. - return await templatePackageCoordinator.EnterInstallFlowAsync(args, context.GetCancellationToken()).ConfigureAwait(false); - } - - protected override InstallCommandArgs ParseContext(ParseResult parseResult) - { - return new InstallCommandArgs(this, parseResult); - } - } - - internal class InstallCommandArgs : GlobalArgs - { - public InstallCommandArgs(BaseInstallCommand installCommand, ParseResult parseResult) : base(installCommand, parseResult) - { - TemplatePackages = parseResult.GetValueForArgument(installCommand.NameArgument) - ?? throw new ArgumentException($"{nameof(parseResult)} should contain at least one argument for {nameof(installCommand.NameArgument)}", nameof(parseResult)); - - //workaround for --install source1 --install source2 case - if (installCommand is LegacyInstallCommand && installCommand.Aliases.Any(alias => TemplatePackages.Contains(alias))) - { - TemplatePackages = TemplatePackages.Where(package => !installCommand.Aliases.Contains(package)).ToList(); - } - - if (!TemplatePackages.Any()) - { - throw new ArgumentException($"{nameof(parseResult)} should contain at least one argument for {nameof(installCommand.NameArgument)}", nameof(parseResult)); - } - - Interactive = parseResult.GetValueForOption(installCommand.InteractiveOption); - AdditionalSources = parseResult.GetValueForOption(installCommand.AddSourceOption); - } - - public IReadOnlyList TemplatePackages { get; } - - public bool Interactive { get; } - - public IReadOnlyList? AdditionalSources { get; } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/Exceptions/InvalidTemplateParametersException.cs b/src/Microsoft.TemplateEngine.Cli/Commands/InvalidTemplateParametersException.cs similarity index 96% rename from src/Microsoft.TemplateEngine.Cli/Commands/Exceptions/InvalidTemplateParametersException.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/InvalidTemplateParametersException.cs index 435dd660e6a..f4e5ce0bc7a 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/Exceptions/InvalidTemplateParametersException.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/InvalidTemplateParametersException.cs @@ -5,7 +5,7 @@ using System.Text; -namespace Microsoft.TemplateEngine.Cli.Commands.Exceptions +namespace Microsoft.TemplateEngine.Cli.Commands { internal class InvalidTemplateParametersException : Exception { diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/ListCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/ListCommand.cs deleted file mode 100644 index 0b2e7b7d15c..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/Commands/ListCommand.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -using System.CommandLine; -using System.CommandLine.Invocation; -using System.CommandLine.Parsing; -using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Edge.Settings; - -namespace Microsoft.TemplateEngine.Cli.Commands -{ - internal class ListCommand : BaseListCommand - { - public ListCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "list") - { - parentCommand.AddNoLegacyUsageValidators(this); - } - } - - internal class LegacyListCommand : BaseListCommand - { - public LegacyListCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "--list") - { - this.IsHidden = true; - this.AddAlias("-l"); - AddValidator(ValidateParentCommandArguments); - - parentCommand.AddNoLegacyUsageValidators(this, except: Filters.Values.Concat(new Symbol[] { ColumnsAllOption, ColumnsOption, parentCommand.ShortNameArgument }).ToArray()); - } - - public override Option ColumnsAllOption => ParentCommand.ColumnsAllOption; - - public override Option> ColumnsOption => ParentCommand.ColumnsOption; - - protected override Option GetFilterOption(FilterOptionDefinition def) - { - return ParentCommand.LegacyFilters[def]; - } - - private string? ValidateParentCommandArguments(CommandResult commandResult) - { - var nameArgumentResult = commandResult.Children.FirstOrDefault(symbol => symbol.Symbol == this.NameArgument); - if (nameArgumentResult == null) - { - return null; - } - return ParentCommand.ValidateShortNameArgumentIsNotUsed(commandResult); - } - } - - internal class BaseListCommand : BaseCommand, IFilterableCommand, ITabularOutputCommand - { - internal static readonly IReadOnlyList SupportedFilters = new List() - { - FilterOptionDefinition.AuthorFilter, - FilterOptionDefinition.BaselineFilter, - FilterOptionDefinition.LanguageFilter, - FilterOptionDefinition.TypeFilter, - FilterOptionDefinition.TagFilter - }; - - internal BaseListCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks, - string commandName) - : base(host, logger, callbacks, commandName, SymbolStrings.Command_List_Description) - { - ParentCommand = parentCommand; - Filters = SetupFilterOptions(SupportedFilters); - - this.AddArgument(NameArgument); - SetupTabularOutputOptions(this); - } - - public virtual Option ColumnsAllOption { get; } = SharedOptionsFactory.CreateColumnsAllOption(); - - public virtual Option> ColumnsOption { get; } = SharedOptionsFactory.CreateColumnsOption(); - - public IReadOnlyDictionary Filters { get; protected set; } - - internal Argument NameArgument { get; } = new("name") - { - Description = SymbolStrings.Command_List_Argument_Name, - Arity = new ArgumentArity(0, 1) - }; - - internal NewCommand ParentCommand { get; } - - protected override async Task ExecuteAsync(ListCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) - { - using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); - TemplateListCoordinator templateListCoordinator = new TemplateListCoordinator( - environmentSettings, - templatePackageManager, - new HostSpecificDataLoader(environmentSettings), - TelemetryLogger); - - //we need to await, otherwise templatePackageManager will be disposed. - return await templateListCoordinator.DisplayTemplateGroupListAsync(args, default).ConfigureAwait(false); - } - - protected override ListCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); - - } - - internal class ListCommandArgs : BaseFilterableArgs, ITabularOutputArgs - { - internal ListCommandArgs(BaseListCommand command, ParseResult parseResult) : base(command, parseResult) - { - string? nameCriteria = parseResult.GetValueForArgument(command.NameArgument); - if (!string.IsNullOrWhiteSpace(nameCriteria)) - { - ListNameCriteria = nameCriteria; - } - // for legacy case new command argument is also accepted - else if (command is LegacyListCommand legacySearchCommand) - { - string? newCommandArgument = parseResult.GetValueForArgument(legacySearchCommand.ParentCommand.ShortNameArgument); - if (!string.IsNullOrWhiteSpace(newCommandArgument)) - { - ListNameCriteria = newCommandArgument; - } - } - (DisplayAllColumns, ColumnsToDisplay) = ParseTabularOutputSettings(command, parseResult); - if (AppliedFilters.Contains(FilterOptionDefinition.LanguageFilter)) - { - Language = GetFilterValue(FilterOptionDefinition.LanguageFilter); - } - } - - public bool DisplayAllColumns { get; } - - public IReadOnlyList? ColumnsToDisplay { get; } - - internal string? ListNameCriteria { get; } - - internal string? Language { get; } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/SearchCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/SearchCommand.cs deleted file mode 100644 index 8485aeff167..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/Commands/SearchCommand.cs +++ /dev/null @@ -1,153 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -using System.CommandLine; -using System.CommandLine.Invocation; -using System.CommandLine.Parsing; -using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Cli.Extensions; -using Microsoft.TemplateEngine.Cli.TemplateSearch; -using Microsoft.TemplateEngine.Edge.Settings; - -namespace Microsoft.TemplateEngine.Cli.Commands -{ - internal class SearchCommand : BaseSearchCommand - { - public SearchCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "search") - { - parentCommand.AddNoLegacyUsageValidators(this); - } - } - - internal class LegacySearchCommand : BaseSearchCommand - { - public LegacySearchCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "--search") - { - this.IsHidden = true; - AddValidator(ValidateParentCommandArguments); - - parentCommand.AddNoLegacyUsageValidators(this, except: Filters.Values.Concat(new Symbol[] { ColumnsAllOption, ColumnsOption, parentCommand.ShortNameArgument }).ToArray()); - } - - public override Option ColumnsAllOption => ParentCommand.ColumnsAllOption; - - public override Option> ColumnsOption => ParentCommand.ColumnsOption; - - protected override Option GetFilterOption(FilterOptionDefinition def) - { - return ParentCommand.LegacyFilters[def]; - } - - private string? ValidateParentCommandArguments(CommandResult commandResult) - { - var nameArgumentResult = commandResult.Children.FirstOrDefault(symbol => symbol.Symbol == this.NameArgument); - if (nameArgumentResult == null) - { - return null; - } - return ParentCommand.ValidateShortNameArgumentIsNotUsed(commandResult); - } - } - - internal class BaseSearchCommand : BaseCommand, IFilterableCommand, ITabularOutputCommand - { - internal static readonly IReadOnlyList SupportedFilters = new List() - { - FilterOptionDefinition.AuthorFilter, - FilterOptionDefinition.BaselineFilter, - FilterOptionDefinition.LanguageFilter, - FilterOptionDefinition.TypeFilter, - FilterOptionDefinition.TagFilter, - FilterOptionDefinition.PackageFilter - }; - - internal BaseSearchCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks, - string commandName) - : base(host, logger, callbacks, commandName, SymbolStrings.Command_Search_Description) - { - ParentCommand = parentCommand; - Filters = SetupFilterOptions(SupportedFilters); - - this.AddArgument(NameArgument); - SetupTabularOutputOptions(this); - } - - public virtual Option ColumnsAllOption { get; } = SharedOptionsFactory.CreateColumnsAllOption(); - - public virtual Option> ColumnsOption { get; } = SharedOptionsFactory.CreateColumnsOption(); - - public IReadOnlyDictionary Filters { get; protected set; } - - internal Argument NameArgument { get; } = new("name") - { - Description = SymbolStrings.Command_Search_Argument_Name, - Arity = new ArgumentArity(0, 1) - }; - - internal NewCommand ParentCommand { get; } - - protected override async Task ExecuteAsync(SearchCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) - { - using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); - //we need to await, otherwise templatePackageManager will be disposed. - return await CliTemplateSearchCoordinator.SearchForTemplateMatchesAsync( - environmentSettings, - templatePackageManager, - args, - environmentSettings.GetDefaultLanguage(), - context.GetCancellationToken()).ConfigureAwait(false); - } - - protected override SearchCommandArgs ParseContext(ParseResult parseResult) - { - return new SearchCommandArgs(this, parseResult); - } - } - - internal class SearchCommandArgs : BaseFilterableArgs, ITabularOutputArgs - { - internal SearchCommandArgs(BaseSearchCommand command, ParseResult parseResult) : base(command, parseResult) - { - string? nameCriteria = parseResult.GetValueForArgument(command.NameArgument); - if (!string.IsNullOrWhiteSpace(nameCriteria)) - { - SearchNameCriteria = nameCriteria; - } - // for legacy case new command argument is also accepted - else if (command is LegacySearchCommand legacySearchCommand) - { - string? newCommandArgument = parseResult.GetValueForArgument(legacySearchCommand.ParentCommand.ShortNameArgument); - if (!string.IsNullOrWhiteSpace(newCommandArgument)) - { - SearchNameCriteria = newCommandArgument; - } - } - (DisplayAllColumns, ColumnsToDisplay) = ParseTabularOutputSettings(command, parseResult); - - if (AppliedFilters.Contains(FilterOptionDefinition.LanguageFilter)) - { - Language = GetFilterValue(FilterOptionDefinition.LanguageFilter); - } - } - - public bool DisplayAllColumns { get; } - - public IReadOnlyList? ColumnsToDisplay { get; } - - internal string? SearchNameCriteria { get; } - - internal string? Language { get; } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/UpdateCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/UpdateCommand.cs deleted file mode 100644 index 90353830be0..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/Commands/UpdateCommand.cs +++ /dev/null @@ -1,137 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -using System.CommandLine; -using System.CommandLine.Invocation; -using System.CommandLine.Parsing; -using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Edge.Settings; - -namespace Microsoft.TemplateEngine.Cli.Commands -{ - internal class UpdateCommand : BaseUpdateCommand - { - public UpdateCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "update", SymbolStrings.Command_Update_Description) - { - parentCommand.AddNoLegacyUsageValidators(this); - this.AddOption(CheckOnlyOption); - } - - internal Option CheckOnlyOption { get; } = new(new[] { "--check-only", "--dry-run" }) - { - Description = SymbolStrings.Command_Update_Option_CheckOnly - }; - } - - internal class LegacyUpdateApplyCommand : BaseUpdateCommand - { - public LegacyUpdateApplyCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "--update-apply", SymbolStrings.Command_Legacy_Update_Check_Description) - { - this.IsHidden = true; - parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); - } - - internal override Option InteractiveOption => ParentCommand.InteractiveOption; - - internal override Option> AddSourceOption => ParentCommand.AddSourceOption; - } - - internal class LegacyUpdateCheckCommand : BaseUpdateCommand - { - public LegacyUpdateCheckCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(parentCommand, host, logger, callbacks, "--update-check", SymbolStrings.Command_Update_Description) - { - this.IsHidden = true; - parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); - } - - internal override Option InteractiveOption => ParentCommand.InteractiveOption; - - internal override Option> AddSourceOption => ParentCommand.AddSourceOption; - } - - internal class BaseUpdateCommand : BaseCommand - { - internal BaseUpdateCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks, - string commandName, - string description) - : base(host, logger, callbacks, commandName, description) - { - ParentCommand = parentCommand; - this.AddOption(InteractiveOption); - this.AddOption(AddSourceOption); - } - - internal virtual Option InteractiveOption { get; } = SharedOptionsFactory.CreateInteractiveOption(); - - internal virtual Option> AddSourceOption { get; } = SharedOptionsFactory.CreateAddSourceOption(); - - protected NewCommand ParentCommand { get; } - - protected override async Task ExecuteAsync(UpdateCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) - { - using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); - TemplatePackageCoordinator templatePackageCoordinator = new TemplatePackageCoordinator( - TelemetryLogger, - environmentSettings, - templatePackageManager); - - //we need to await, otherwise templatePackageManager will be disposed. - return await templatePackageCoordinator.EnterUpdateFlowAsync(args, context.GetCancellationToken()).ConfigureAwait(false); - } - - protected override UpdateCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); - } - - internal class UpdateCommandArgs : GlobalArgs - { - public UpdateCommandArgs(BaseUpdateCommand command, ParseResult parseResult) : base(command, parseResult) - { - if (command is UpdateCommand updateCommand) - { - CheckOnly = parseResult.GetValueForOption(updateCommand.CheckOnlyOption); - } - else if (command is LegacyUpdateCheckCommand) - { - CheckOnly = true; - } - else if (command is LegacyUpdateApplyCommand) - { - CheckOnly = false; - } - else - { - throw new ArgumentException($"Unsupported type {command.GetType().FullName}", nameof(command)); - } - - Interactive = parseResult.GetValueForOption(command.InteractiveOption); - AdditionalSources = parseResult.GetValueForOption(command.AddSourceOption); - } - - public bool CheckOnly { get; } - - public bool Interactive { get; } - - public IReadOnlyList? AdditionalSources { get; } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommand.cs new file mode 100644 index 00000000000..83187683144 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommand.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class AliasAddCommand : BaseAliasAddCommand + { + internal AliasAddCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "add") + { + IsHidden = true; + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommandArgs.cs new file mode 100644 index 00000000000..ef671536e5e --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasAddCommandArgs.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class AliasAddCommandArgs : GlobalArgs + { + public AliasAddCommandArgs(BaseAliasAddCommand command, ParseResult parseResult) : base(command, parseResult) + { + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/AliasCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommand.cs similarity index 86% rename from src/Microsoft.TemplateEngine.Cli/Commands/AliasCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommand.cs index 728db64d0b9..cec61a2e4e7 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/AliasCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommand.cs @@ -26,11 +26,4 @@ internal AliasCommand( protected override AliasCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); } - - internal class AliasCommandArgs : GlobalArgs - { - public AliasCommandArgs(AliasCommand command, ParseResult parseResult) : base(command, parseResult) - { - } - } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommandArgs.cs new file mode 100644 index 00000000000..fb508e272b2 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommandArgs.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class AliasCommandArgs : GlobalArgs + { + public AliasCommandArgs(AliasCommand command, ParseResult parseResult) : base(command, parseResult) + { + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommand.cs new file mode 100644 index 00000000000..741192883f2 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommand.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class AliasShowCommand : BaseAliasShowCommand + { + internal AliasShowCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "show") + { + IsHidden = true; + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommandArgs.cs new file mode 100644 index 00000000000..1618e4e9770 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasShowCommandArgs.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class AliasShowCommandArgs : GlobalArgs + { + public AliasShowCommandArgs(BaseAliasShowCommand command, ParseResult parseResult) : base(command, parseResult) + { + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/AliasAddCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasAddCommand.cs similarity index 56% rename from src/Microsoft.TemplateEngine.Cli/Commands/AliasAddCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasAddCommand.cs index 85a7f6b173b..ed8922e25d5 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/AliasAddCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasAddCommand.cs @@ -9,23 +9,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - internal class AliasAddCommand : BaseAliasAddCommand - { - internal AliasAddCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "add") - { - IsHidden = true; - } - } - - internal class LegacyAliasAddCommand : BaseAliasAddCommand - { - internal LegacyAliasAddCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "--alias") - { - AddAlias("-a"); - IsHidden = true; - } - } - internal class BaseAliasAddCommand : BaseCommand { internal BaseAliasAddCommand( @@ -39,11 +22,4 @@ internal BaseAliasAddCommand( protected override AliasAddCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); } - - internal class AliasAddCommandArgs : GlobalArgs - { - public AliasAddCommandArgs(BaseAliasAddCommand command, ParseResult parseResult) : base(command, parseResult) - { - } - } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/AliasShowCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasShowCommand.cs similarity index 56% rename from src/Microsoft.TemplateEngine.Cli/Commands/AliasShowCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasShowCommand.cs index b6253cf69ac..26429f1795d 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/AliasShowCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/BaseAliasShowCommand.cs @@ -9,22 +9,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - internal class AliasShowCommand : BaseAliasShowCommand - { - internal AliasShowCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "show") - { - IsHidden = true; - } - } - - internal class LegacyAliasShowCommand : BaseAliasShowCommand - { - internal LegacyAliasShowCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "--show-alias") - { - IsHidden = true; - } - } - internal class BaseAliasShowCommand : BaseCommand { internal BaseAliasShowCommand( @@ -38,11 +22,4 @@ internal BaseAliasShowCommand( protected override AliasShowCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); } - - internal class AliasShowCommandArgs : GlobalArgs - { - public AliasShowCommandArgs(BaseAliasShowCommand command, ParseResult parseResult) : base(command, parseResult) - { - } - } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasAddCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasAddCommand.cs new file mode 100644 index 00000000000..0343de89969 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasAddCommand.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyAliasAddCommand : BaseAliasAddCommand + { + internal LegacyAliasAddCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "--alias") + { + AddAlias("-a"); + IsHidden = true; + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasShowCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasShowCommand.cs new file mode 100644 index 00000000000..59d277803e2 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/alias/LegacyAliasShowCommand.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyAliasShowCommand : BaseAliasShowCommand + { + internal LegacyAliasShowCommand(ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) : base(host, logger, callbacks, "--show-alias") + { + IsHidden = true; + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/CombinedChoiceTemplateParameter.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/CombinedChoiceTemplateParameter.cs similarity index 100% rename from src/Microsoft.TemplateEngine.Cli/CombinedChoiceTemplateParameter.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/CombinedChoiceTemplateParameter.cs diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.Help.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs similarity index 100% rename from src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.Help.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.HelpUtils.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.HelpUtils.cs similarity index 100% rename from src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.HelpUtils.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.HelpUtils.cs diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.NoMatchHandling.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.NoMatchHandling.cs similarity index 99% rename from src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.NoMatchHandling.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.NoMatchHandling.cs index 8cca9fbf263..b57457c1100 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.NoMatchHandling.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.NoMatchHandling.cs @@ -5,7 +5,6 @@ using System.CommandLine; using System.CommandLine.Parsing; -using System.Security.Cryptography.X509Certificates; using System.Text; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Edge.Settings; diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.TabCompletion.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.TabCompletion.cs similarity index 98% rename from src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.TabCompletion.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.TabCompletion.cs index da4f55fd7fa..dd91e52003e 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.TabCompletion.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.TabCompletion.cs @@ -6,7 +6,6 @@ using System.CommandLine.Completions; using System.CommandLine.Parsing; using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Cli.Commands.Exceptions; using Microsoft.TemplateEngine.Edge.Settings; namespace Microsoft.TemplateEngine.Cli.Commands diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs similarity index 96% rename from src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs index d6ef5b1bbe4..20cc52dcf76 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/InstantiateCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs @@ -10,7 +10,6 @@ using Microsoft.Extensions.Logging; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Abstractions.TemplatePackage; -using Microsoft.TemplateEngine.Cli.Commands.Exceptions; using Microsoft.TemplateEngine.Cli.Extensions; using Microsoft.TemplateEngine.Cli.TabularOutput; using Microsoft.TemplateEngine.Edge.Settings; @@ -438,28 +437,4 @@ private HashSet ReparseForDefaultLanguage( } } } - - internal class InstantiateCommandArgs : GlobalArgs - { - public InstantiateCommandArgs(InstantiateCommand command, ParseResult parseResult) : base(command, parseResult) - { - RemainingArguments = parseResult.GetValueForArgument(command.RemainingArguments) ?? Array.Empty(); - ShortName = parseResult.GetValueForArgument(command.ShortNameArgument); - - var tokens = new List(); - if (!string.IsNullOrWhiteSpace(ShortName)) - { - tokens.Add(ShortName); - } - tokens.AddRange(RemainingArguments); - TokensToInvoke = tokens.ToArray(); - - } - - internal string? ShortName { get; } - - internal string[] RemainingArguments { get; } - - internal string[] TokensToInvoke { get; } - } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommandArgs.cs new file mode 100644 index 00000000000..369f31e980a --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommandArgs.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class InstantiateCommandArgs : GlobalArgs + { + public InstantiateCommandArgs(InstantiateCommand command, ParseResult parseResult) : base(command, parseResult) + { + RemainingArguments = parseResult.GetValueForArgument(command.RemainingArguments) ?? Array.Empty(); + ShortName = parseResult.GetValueForArgument(command.ShortNameArgument); + + var tokens = new List(); + if (!string.IsNullOrWhiteSpace(ShortName)) + { + tokens.Add(ShortName); + } + tokens.AddRange(RemainingArguments); + TokensToInvoke = tokens.ToArray(); + + } + + internal string? ShortName { get; } + + internal string[] RemainingArguments { get; } + + internal string[] TokensToInvoke { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateOptionResult.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/InvalidTemplateOptionResult.cs similarity index 84% rename from src/Microsoft.TemplateEngine.Cli/Commands/TemplateOptionResult.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/InvalidTemplateOptionResult.cs index cfb5f17223f..78f643b0854 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateOptionResult.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/InvalidTemplateOptionResult.cs @@ -9,50 +9,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - /// - /// The class represents the information about the template option used when executing the command. - /// - internal class TemplateOptionResult - { - internal TemplateOptionResult( - TemplateOption? templateOption, - string inputFormat, - string? specifiedValue) - { - TemplateOption = templateOption; - InputFormat = inputFormat; - SpecifiedValue = specifiedValue; - } - - /// - /// the alias used in CLI for parameter. - /// - internal string InputFormat { get; } - - /// - /// The value specified for the parameter in CLI. - /// - internal string? SpecifiedValue { get; } - - internal TemplateOption? TemplateOption { get; } - - internal static TemplateOptionResult? FromParseResult(TemplateOption option, ParseResult parseResult) - { - OptionResult? optionResult = parseResult.FindResultFor(option.Option); - - if (optionResult == null) - { - //option is not specified - return null; - } - - return new TemplateOptionResult( - option, - optionResult.Token.Value ?? string.Empty, - optionResult.GetValueOrDefault()); - } - } - /// /// The class represents the information about the invalid template option used when executing the command. /// diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs similarity index 98% rename from src/Microsoft.TemplateEngine.Cli/Commands/TemplateCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs index ac30bd10109..037ebbb2434 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs @@ -7,7 +7,6 @@ using System.CommandLine.Invocation; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Abstractions.Installer; -using Microsoft.TemplateEngine.Cli.Commands.Exceptions; using Microsoft.TemplateEngine.Cli.Extensions; using Microsoft.TemplateEngine.Cli.PostActionProcessors; using Microsoft.TemplateEngine.Edge.Settings; @@ -157,7 +156,7 @@ public TemplateCommand( public async Task InvokeAsync(InvocationContext context) { - TemplateArgs args = new TemplateArgs(this, context.ParseResult); + TemplateCommandArgs args = new TemplateCommandArgs(this, context.ParseResult); TemplateInvoker invoker = new TemplateInvoker(_environmentSettings, _instantiateCommand.TelemetryLogger, () => Console.ReadLine() ?? string.Empty, _instantiateCommand.Callbacks); if (!args.NoUpdateCheck) diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs similarity index 97% rename from src/Microsoft.TemplateEngine.Cli/Commands/TemplateArgs.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs index 264c13c95da..a61846b5402 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateArgs.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommandArgs.cs @@ -7,13 +7,13 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - internal class TemplateArgs + internal class TemplateCommandArgs { private readonly ParseResult _parseResult; private readonly TemplateCommand _command; private Dictionary _templateOptions = new Dictionary(); - public TemplateArgs(TemplateCommand command, ParseResult parseResult) + public TemplateCommandArgs(TemplateCommand command, ParseResult parseResult) { _parseResult = parseResult ?? throw new ArgumentNullException(nameof(parseResult)); _command = command ?? throw new ArgumentNullException(nameof(command)); diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateOption.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateOption.cs similarity index 100% rename from src/Microsoft.TemplateEngine.Cli/Commands/TemplateOption.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateOption.cs diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateOptionResult.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateOptionResult.cs new file mode 100644 index 00000000000..6a6007d3843 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateOptionResult.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + /// + /// The class represents the information about the template option used when executing the command. + /// + internal class TemplateOptionResult + { + internal TemplateOptionResult( + TemplateOption? templateOption, + string inputFormat, + string? specifiedValue) + { + TemplateOption = templateOption; + InputFormat = inputFormat; + SpecifiedValue = specifiedValue; + } + + /// + /// the alias used in CLI for parameter. + /// + internal string InputFormat { get; } + + /// + /// The value specified for the parameter in CLI. + /// + internal string? SpecifiedValue { get; } + + internal TemplateOption? TemplateOption { get; } + + internal static TemplateOptionResult? FromParseResult(TemplateOption option, ParseResult parseResult) + { + OptionResult? optionResult = parseResult.FindResultFor(option.Option); + + if (optionResult == null) + { + //option is not specified + return null; + } + + return new TemplateOptionResult( + option, + optionResult.Token.Value ?? string.Empty, + optionResult.GetValueOrDefault()); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/TemplateResult.cs b/src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateResult.cs similarity index 100% rename from src/Microsoft.TemplateEngine.Cli/Commands/TemplateResult.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/create/TemplateResult.cs diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/install/BaseInstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/install/BaseInstallCommand.cs new file mode 100644 index 00000000000..0dac4b736ce --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/install/BaseInstallCommand.cs @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; +using Microsoft.TemplateEngine.Edge.Settings; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal abstract class BaseInstallCommand : BaseCommand + { + internal BaseInstallCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks, + string commandName) + : base(host, logger, callbacks, commandName, SymbolStrings.Command_Install_Description) + { + ParentCommand = parentCommand; + this.AddArgument(NameArgument); + this.AddOption(InteractiveOption); + this.AddOption(AddSourceOption); + } + + internal Argument> NameArgument { get; } = new("package") + { + Description = SymbolStrings.Command_Install_Argument_Package, + Arity = new ArgumentArity(1, 99) + }; + + internal virtual Option InteractiveOption { get; } = SharedOptionsFactory.CreateInteractiveOption(); + + internal virtual Option> AddSourceOption { get; } = SharedOptionsFactory.CreateAddSourceOption(); + + protected NewCommand ParentCommand { get; } + + protected override async Task ExecuteAsync(InstallCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) + { + using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); + TemplatePackageCoordinator templatePackageCoordinator = new TemplatePackageCoordinator( + TelemetryLogger, + environmentSettings, + templatePackageManager); + + //we need to await, otherwise templatePackageManager will be disposed. + return await templatePackageCoordinator.EnterInstallFlowAsync(args, context.GetCancellationToken()).ConfigureAwait(false); + } + + protected override InstallCommandArgs ParseContext(ParseResult parseResult) + { + return new InstallCommandArgs(this, parseResult); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommand.cs new file mode 100644 index 00000000000..dd2dfa42a49 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommand.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class InstallCommand : BaseInstallCommand + { + public InstallCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "install") + { + parentCommand.AddNoLegacyUsageValidators(this); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommandArgs.cs new file mode 100644 index 00000000000..1b23cf34473 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/install/InstallCommandArgs.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class InstallCommandArgs : GlobalArgs + { + public InstallCommandArgs(BaseInstallCommand installCommand, ParseResult parseResult) : base(installCommand, parseResult) + { + TemplatePackages = parseResult.GetValueForArgument(installCommand.NameArgument) + ?? throw new ArgumentException($"{nameof(parseResult)} should contain at least one argument for {nameof(installCommand.NameArgument)}", nameof(parseResult)); + + //workaround for --install source1 --install source2 case + if (installCommand is LegacyInstallCommand && installCommand.Aliases.Any(alias => TemplatePackages.Contains(alias))) + { + TemplatePackages = TemplatePackages.Where(package => !installCommand.Aliases.Contains(package)).ToList(); + } + + if (!TemplatePackages.Any()) + { + throw new ArgumentException($"{nameof(parseResult)} should contain at least one argument for {nameof(installCommand.NameArgument)}", nameof(parseResult)); + } + + Interactive = parseResult.GetValueForOption(installCommand.InteractiveOption); + AdditionalSources = parseResult.GetValueForOption(installCommand.AddSourceOption); + } + + public IReadOnlyList TemplatePackages { get; } + + public bool Interactive { get; } + + public IReadOnlyList? AdditionalSources { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/install/LegacyInstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/install/LegacyInstallCommand.cs new file mode 100644 index 00000000000..c64a624d02d --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/install/LegacyInstallCommand.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyInstallCommand : BaseInstallCommand + { + public LegacyInstallCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "--install") + { + this.IsHidden = true; + this.AddAlias("-i"); + + parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); + } + + internal override Option InteractiveOption => ParentCommand.InteractiveOption; + + internal override Option> AddSourceOption => ParentCommand.AddSourceOption; + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/list/BaseListCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/list/BaseListCommand.cs new file mode 100644 index 00000000000..0c3b6e5e3f0 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/list/BaseListCommand.cs @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; +using Microsoft.TemplateEngine.Edge.Settings; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class BaseListCommand : BaseCommand, IFilterableCommand, ITabularOutputCommand + { + internal static readonly IReadOnlyList SupportedFilters = new List() + { + FilterOptionDefinition.AuthorFilter, + FilterOptionDefinition.BaselineFilter, + FilterOptionDefinition.LanguageFilter, + FilterOptionDefinition.TypeFilter, + FilterOptionDefinition.TagFilter + }; + + internal BaseListCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks, + string commandName) + : base(host, logger, callbacks, commandName, SymbolStrings.Command_List_Description) + { + ParentCommand = parentCommand; + Filters = SetupFilterOptions(SupportedFilters); + + this.AddArgument(NameArgument); + SetupTabularOutputOptions(this); + } + + public virtual Option ColumnsAllOption { get; } = SharedOptionsFactory.CreateColumnsAllOption(); + + public virtual Option> ColumnsOption { get; } = SharedOptionsFactory.CreateColumnsOption(); + + public IReadOnlyDictionary Filters { get; protected set; } + + internal Argument NameArgument { get; } = new("name") + { + Description = SymbolStrings.Command_List_Argument_Name, + Arity = new ArgumentArity(0, 1) + }; + + internal NewCommand ParentCommand { get; } + + protected override async Task ExecuteAsync(ListCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) + { + using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); + TemplateListCoordinator templateListCoordinator = new TemplateListCoordinator( + environmentSettings, + templatePackageManager, + new HostSpecificDataLoader(environmentSettings), + TelemetryLogger); + + //we need to await, otherwise templatePackageManager will be disposed. + return await templateListCoordinator.DisplayTemplateGroupListAsync(args, default).ConfigureAwait(false); + } + + protected override ListCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); + + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/list/LegacyListCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/list/LegacyListCommand.cs new file mode 100644 index 00000000000..dc5c2367901 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/list/LegacyListCommand.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyListCommand : BaseListCommand + { + public LegacyListCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "--list") + { + this.IsHidden = true; + this.AddAlias("-l"); + AddValidator(ValidateParentCommandArguments); + + parentCommand.AddNoLegacyUsageValidators(this, except: Filters.Values.Concat(new Symbol[] { ColumnsAllOption, ColumnsOption, parentCommand.ShortNameArgument }).ToArray()); + } + + public override Option ColumnsAllOption => ParentCommand.ColumnsAllOption; + + public override Option> ColumnsOption => ParentCommand.ColumnsOption; + + protected override Option GetFilterOption(FilterOptionDefinition def) + { + return ParentCommand.LegacyFilters[def]; + } + + private string? ValidateParentCommandArguments(CommandResult commandResult) + { + var nameArgumentResult = commandResult.Children.FirstOrDefault(symbol => symbol.Symbol == this.NameArgument); + if (nameArgumentResult == null) + { + return null; + } + return ParentCommand.ValidateShortNameArgumentIsNotUsed(commandResult); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommand.cs new file mode 100644 index 00000000000..e51ddeec7d6 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommand.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class ListCommand : BaseListCommand + { + public ListCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "list") + { + parentCommand.AddNoLegacyUsageValidators(this); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommandArgs.cs new file mode 100644 index 00000000000..29ff2b2d39f --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/list/ListCommandArgs.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class ListCommandArgs : BaseFilterableArgs, ITabularOutputArgs + { + internal ListCommandArgs(BaseListCommand command, ParseResult parseResult) : base(command, parseResult) + { + string? nameCriteria = parseResult.GetValueForArgument(command.NameArgument); + if (!string.IsNullOrWhiteSpace(nameCriteria)) + { + ListNameCriteria = nameCriteria; + } + // for legacy case new command argument is also accepted + else if (command is LegacyListCommand legacySearchCommand) + { + string? newCommandArgument = parseResult.GetValueForArgument(legacySearchCommand.ParentCommand.ShortNameArgument); + if (!string.IsNullOrWhiteSpace(newCommandArgument)) + { + ListNameCriteria = newCommandArgument; + } + } + (DisplayAllColumns, ColumnsToDisplay) = ParseTabularOutputSettings(command, parseResult); + if (AppliedFilters.Contains(FilterOptionDefinition.LanguageFilter)) + { + Language = GetFilterValue(FilterOptionDefinition.LanguageFilter); + } + } + + public bool DisplayAllColumns { get; } + + public IReadOnlyList? ColumnsToDisplay { get; } + + internal string? ListNameCriteria { get; } + + internal string? Language { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/search/BaseSearchCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/search/BaseSearchCommand.cs new file mode 100644 index 00000000000..13502e83c42 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/search/BaseSearchCommand.cs @@ -0,0 +1,74 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; +using Microsoft.TemplateEngine.Cli.Extensions; +using Microsoft.TemplateEngine.Cli.TemplateSearch; +using Microsoft.TemplateEngine.Edge.Settings; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class BaseSearchCommand : BaseCommand, IFilterableCommand, ITabularOutputCommand + { + internal static readonly IReadOnlyList SupportedFilters = new List() + { + FilterOptionDefinition.AuthorFilter, + FilterOptionDefinition.BaselineFilter, + FilterOptionDefinition.LanguageFilter, + FilterOptionDefinition.TypeFilter, + FilterOptionDefinition.TagFilter, + FilterOptionDefinition.PackageFilter + }; + + internal BaseSearchCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks, + string commandName) + : base(host, logger, callbacks, commandName, SymbolStrings.Command_Search_Description) + { + ParentCommand = parentCommand; + Filters = SetupFilterOptions(SupportedFilters); + + this.AddArgument(NameArgument); + SetupTabularOutputOptions(this); + } + + public virtual Option ColumnsAllOption { get; } = SharedOptionsFactory.CreateColumnsAllOption(); + + public virtual Option> ColumnsOption { get; } = SharedOptionsFactory.CreateColumnsOption(); + + public IReadOnlyDictionary Filters { get; protected set; } + + internal Argument NameArgument { get; } = new("name") + { + Description = SymbolStrings.Command_Search_Argument_Name, + Arity = new ArgumentArity(0, 1) + }; + + internal NewCommand ParentCommand { get; } + + protected override async Task ExecuteAsync(SearchCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) + { + using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); + //we need to await, otherwise templatePackageManager will be disposed. + return await CliTemplateSearchCoordinator.SearchForTemplateMatchesAsync( + environmentSettings, + templatePackageManager, + args, + environmentSettings.GetDefaultLanguage(), + context.GetCancellationToken()).ConfigureAwait(false); + } + + protected override SearchCommandArgs ParseContext(ParseResult parseResult) + { + return new SearchCommandArgs(this, parseResult); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/search/LegacySearchCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/search/LegacySearchCommand.cs new file mode 100644 index 00000000000..c83a2dbf415 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/search/LegacySearchCommand.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacySearchCommand : BaseSearchCommand + { + public LegacySearchCommand(NewCommand parentCommand, ITemplateEngineHost host, ITelemetryLogger logger, NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "--search") + { + this.IsHidden = true; + AddValidator(ValidateParentCommandArguments); + + parentCommand.AddNoLegacyUsageValidators(this, except: Filters.Values.Concat(new Symbol[] { ColumnsAllOption, ColumnsOption, parentCommand.ShortNameArgument }).ToArray()); + } + + public override Option ColumnsAllOption => ParentCommand.ColumnsAllOption; + + public override Option> ColumnsOption => ParentCommand.ColumnsOption; + + protected override Option GetFilterOption(FilterOptionDefinition def) + { + return ParentCommand.LegacyFilters[def]; + } + + private string? ValidateParentCommandArguments(CommandResult commandResult) + { + var nameArgumentResult = commandResult.Children.FirstOrDefault(symbol => symbol.Symbol == this.NameArgument); + if (nameArgumentResult == null) + { + return null; + } + return ParentCommand.ValidateShortNameArgumentIsNotUsed(commandResult); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommand.cs new file mode 100644 index 00000000000..5fa6b86512b --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommand.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class SearchCommand : BaseSearchCommand + { + public SearchCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "search") + { + parentCommand.AddNoLegacyUsageValidators(this); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommandArgs.cs new file mode 100644 index 00000000000..e0c982ad0a5 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/search/SearchCommandArgs.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class SearchCommandArgs : BaseFilterableArgs, ITabularOutputArgs + { + internal SearchCommandArgs(BaseSearchCommand command, ParseResult parseResult) : base(command, parseResult) + { + string? nameCriteria = parseResult.GetValueForArgument(command.NameArgument); + if (!string.IsNullOrWhiteSpace(nameCriteria)) + { + SearchNameCriteria = nameCriteria; + } + // for legacy case new command argument is also accepted + else if (command is LegacySearchCommand legacySearchCommand) + { + string? newCommandArgument = parseResult.GetValueForArgument(legacySearchCommand.ParentCommand.ShortNameArgument); + if (!string.IsNullOrWhiteSpace(newCommandArgument)) + { + SearchNameCriteria = newCommandArgument; + } + } + (DisplayAllColumns, ColumnsToDisplay) = ParseTabularOutputSettings(command, parseResult); + + if (AppliedFilters.Contains(FilterOptionDefinition.LanguageFilter)) + { + Language = GetFilterValue(FilterOptionDefinition.LanguageFilter); + } + } + + public bool DisplayAllColumns { get; } + + public IReadOnlyList? ColumnsToDisplay { get; } + + internal string? SearchNameCriteria { get; } + + internal string? Language { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/UninstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/BaseUninstallCommand.cs similarity index 53% rename from src/Microsoft.TemplateEngine.Cli/Commands/UninstallCommand.cs rename to src/Microsoft.TemplateEngine.Cli/Commands/uninstall/BaseUninstallCommand.cs index 6e452b86bec..5f5e292075a 100644 --- a/src/Microsoft.TemplateEngine.Cli/Commands/UninstallCommand.cs +++ b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/BaseUninstallCommand.cs @@ -11,35 +11,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - internal class UninstallCommand : BaseUninstallCommand - { - public UninstallCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(host, logger, callbacks, "uninstall") - { - parentCommand.AddNoLegacyUsageValidators(this); - } - } - - internal class LegacyUninstallCommand : BaseUninstallCommand - { - public LegacyUninstallCommand( - NewCommand parentCommand, - ITemplateEngineHost host, - ITelemetryLogger logger, - NewCommandCallbacks callbacks) - : base(host, logger, callbacks, "--uninstall") - { - this.IsHidden = true; - this.AddAlias("-u"); - - parentCommand.AddNoLegacyUsageValidators(this); - } - } - internal class BaseUninstallCommand : BaseCommand { internal BaseUninstallCommand( @@ -74,20 +45,4 @@ protected override UninstallCommandArgs ParseContext(ParseResult parseResult) return new UninstallCommandArgs(this, parseResult); } } - - internal class UninstallCommandArgs : GlobalArgs - { - public UninstallCommandArgs(BaseUninstallCommand uninstallCommand, ParseResult parseResult) : base(uninstallCommand, parseResult) - { - TemplatePackages = parseResult.GetValueForArgument(uninstallCommand.NameArgument) ?? Array.Empty(); - - //workaround for --install source1 --install source2 case - if (uninstallCommand is LegacyUninstallCommand && uninstallCommand.Aliases.Any(alias => TemplatePackages.Contains(alias))) - { - TemplatePackages = TemplatePackages.Where(package => !uninstallCommand.Aliases.Contains(package)).ToList(); - } - } - - public IReadOnlyList TemplatePackages { get; } - } } diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/LegacyUninstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/LegacyUninstallCommand.cs new file mode 100644 index 00000000000..2a09dbd08a2 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/LegacyUninstallCommand.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyUninstallCommand : BaseUninstallCommand + { + public LegacyUninstallCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(host, logger, callbacks, "--uninstall") + { + this.IsHidden = true; + this.AddAlias("-u"); + + parentCommand.AddNoLegacyUsageValidators(this); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommand.cs new file mode 100644 index 00000000000..9123a56cb46 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommand.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class UninstallCommand : BaseUninstallCommand + { + public UninstallCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(host, logger, callbacks, "uninstall") + { + parentCommand.AddNoLegacyUsageValidators(this); + } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommandArgs.cs new file mode 100644 index 00000000000..12ce4920168 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/uninstall/UninstallCommandArgs.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class UninstallCommandArgs : GlobalArgs + { + public UninstallCommandArgs(BaseUninstallCommand uninstallCommand, ParseResult parseResult) : base(uninstallCommand, parseResult) + { + TemplatePackages = parseResult.GetValueForArgument(uninstallCommand.NameArgument) ?? Array.Empty(); + + //workaround for --install source1 --install source2 case + if (uninstallCommand is LegacyUninstallCommand && uninstallCommand.Aliases.Any(alias => TemplatePackages.Contains(alias))) + { + TemplatePackages = TemplatePackages.Where(package => !uninstallCommand.Aliases.Contains(package)).ToList(); + } + } + + public IReadOnlyList TemplatePackages { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/update/BaseUpdateCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/update/BaseUpdateCommand.cs new file mode 100644 index 00000000000..18a1fbcde70 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/update/BaseUpdateCommand.cs @@ -0,0 +1,50 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; +using Microsoft.TemplateEngine.Edge.Settings; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class BaseUpdateCommand : BaseCommand + { + internal BaseUpdateCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks, + string commandName, + string description) + : base(host, logger, callbacks, commandName, description) + { + ParentCommand = parentCommand; + this.AddOption(InteractiveOption); + this.AddOption(AddSourceOption); + } + + internal virtual Option InteractiveOption { get; } = SharedOptionsFactory.CreateInteractiveOption(); + + internal virtual Option> AddSourceOption { get; } = SharedOptionsFactory.CreateAddSourceOption(); + + protected NewCommand ParentCommand { get; } + + protected override async Task ExecuteAsync(UpdateCommandArgs args, IEngineEnvironmentSettings environmentSettings, InvocationContext context) + { + using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); + TemplatePackageCoordinator templatePackageCoordinator = new TemplatePackageCoordinator( + TelemetryLogger, + environmentSettings, + templatePackageManager); + + //we need to await, otherwise templatePackageManager will be disposed. + return await templatePackageCoordinator.EnterUpdateFlowAsync(args, context.GetCancellationToken()).ConfigureAwait(false); + } + + protected override UpdateCommandArgs ParseContext(ParseResult parseResult) => new(this, parseResult); + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateApplyCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateApplyCommand.cs new file mode 100644 index 00000000000..1db0387c05e --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateApplyCommand.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyUpdateApplyCommand : BaseUpdateCommand + { + public LegacyUpdateApplyCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "--update-apply", SymbolStrings.Command_Legacy_Update_Check_Description) + { + this.IsHidden = true; + parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); + } + + internal override Option InteractiveOption => ParentCommand.InteractiveOption; + + internal override Option> AddSourceOption => ParentCommand.AddSourceOption; + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateCheckCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateCheckCommand.cs new file mode 100644 index 00000000000..dc06edce900 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/update/LegacyUpdateCheckCommand.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class LegacyUpdateCheckCommand : BaseUpdateCommand + { + public LegacyUpdateCheckCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "--update-check", SymbolStrings.Command_Update_Description) + { + this.IsHidden = true; + parentCommand.AddNoLegacyUsageValidators(this, except: new Option[] { InteractiveOption, AddSourceOption }); + } + + internal override Option InteractiveOption => ParentCommand.InteractiveOption; + + internal override Option> AddSourceOption => ParentCommand.AddSourceOption; + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommand.cs b/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommand.cs new file mode 100644 index 00000000000..b52412a900f --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommand.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine; +using System.CommandLine.Parsing; +using Microsoft.TemplateEngine.Abstractions; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class UpdateCommand : BaseUpdateCommand + { + public UpdateCommand( + NewCommand parentCommand, + ITemplateEngineHost host, + ITelemetryLogger logger, + NewCommandCallbacks callbacks) + : base(parentCommand, host, logger, callbacks, "update", SymbolStrings.Command_Update_Description) + { + parentCommand.AddNoLegacyUsageValidators(this); + this.AddOption(CheckOnlyOption); + } + + internal Option CheckOnlyOption { get; } = new(new[] { "--check-only", "--dry-run" }) + { + Description = SymbolStrings.Command_Update_Option_CheckOnly + }; + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommandArgs.cs b/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommandArgs.cs new file mode 100644 index 00000000000..d8cf33e3796 --- /dev/null +++ b/src/Microsoft.TemplateEngine.Cli/Commands/update/UpdateCommandArgs.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.CommandLine.Parsing; + +namespace Microsoft.TemplateEngine.Cli.Commands +{ + internal class UpdateCommandArgs : GlobalArgs + { + public UpdateCommandArgs(BaseUpdateCommand command, ParseResult parseResult) : base(command, parseResult) + { + if (command is UpdateCommand updateCommand) + { + CheckOnly = parseResult.GetValueForOption(updateCommand.CheckOnlyOption); + } + else if (command is LegacyUpdateCheckCommand) + { + CheckOnly = true; + } + else if (command is LegacyUpdateApplyCommand) + { + CheckOnly = false; + } + else + { + throw new ArgumentException($"Unsupported type {command.GetType().FullName}", nameof(command)); + } + + Interactive = parseResult.GetValueForOption(command.InteractiveOption); + AdditionalSources = parseResult.GetValueForOption(command.AddSourceOption); + } + + public bool CheckOnly { get; } + + public bool Interactive { get; } + + public IReadOnlyList? AdditionalSources { get; } + } +} diff --git a/src/Microsoft.TemplateEngine.Cli/PublicAPI.Shipped.txt b/src/Microsoft.TemplateEngine.Cli/PublicAPI.Shipped.txt index 024377f8ad6..a645ec62f23 100644 --- a/src/Microsoft.TemplateEngine.Cli/PublicAPI.Shipped.txt +++ b/src/Microsoft.TemplateEngine.Cli/PublicAPI.Shipped.txt @@ -1,6 +1,4 @@ #nullable enable -Microsoft.TemplateEngine.Cli.CommandParserException -Microsoft.TemplateEngine.Cli.CommandParserException.Argument.get -> string! Microsoft.TemplateEngine.Cli.Components Microsoft.TemplateEngine.Cli.HostSpecificDataLoader Microsoft.TemplateEngine.Cli.HostSpecificDataLoader.HostSpecificDataLoader(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings! engineEnvironment) -> void diff --git a/src/Microsoft.TemplateEngine.Cli/TableFormatter.cs b/src/Microsoft.TemplateEngine.Cli/TableFormatter.cs deleted file mode 100644 index 36b7ef88e2a..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/TableFormatter.cs +++ /dev/null @@ -1,79 +0,0 @@ -// 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 class TableFormatter - { - internal static void Print(IEnumerable items, string noItemsMessage, string columnPad, char header, Dictionary> dictionary) - { - List[] columns = new List[dictionary.Count]; - - for (int i = 0; i < dictionary.Count; ++i) - { - columns[i] = new List(); - } - - string[] headers = new string[dictionary.Count]; - int[] columnWidths = new int[dictionary.Count]; - int valueCount = 0; - - foreach (T item in items) - { - int index = 0; - foreach (KeyValuePair> act in dictionary) - { - headers[index] = act.Key; - columns[index++].Add(act.Value(item)?.ToString() ?? "(null)"); - } - ++valueCount; - } - - if (valueCount > 0) - { - for (int i = 0; i < columns.Length; ++i) - { - columnWidths[i] = Math.Max(columns[i].Max(x => x.Length), headers[i].Length); - } - } - else - { - int index = 0; - foreach (KeyValuePair> act in dictionary) - { - headers[index] = act.Key; - columnWidths[index++] = act.Key.Length; - } - } - - int headerWidth = columnWidths.Sum() + columnPad.Length * (dictionary.Count - 1); - - for (int i = 0; i < headers.Length - 1; ++i) - { - Reporter.Output.Write(headers[i].PadRight(columnWidths[i])); - Reporter.Output.Write(columnPad); - } - - Reporter.Output.WriteLine(headers[headers.Length - 1]); - Reporter.Output.WriteLine("".PadRight(headerWidth, header)); - - for (int i = 0; i < valueCount; ++i) - { - for (int j = 0; j < columns.Length - 1; ++j) - { - Reporter.Output.Write(columns[j][i].PadRight(columnWidths[j])); - Reporter.Output.Write(columnPad); - } - - Reporter.Output.WriteLine(columns[headers.Length - 1][i]); - } - - if (valueCount == 0) - { - Reporter.Output.WriteLine(noItemsMessage); - } - - Reporter.Output.WriteLine(" "); - } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/TemplateGroupParameterSet.cs b/src/Microsoft.TemplateEngine.Cli/TemplateGroupParameterSet.cs deleted file mode 100644 index daeeb68ae56..00000000000 --- a/src/Microsoft.TemplateEngine.Cli/TemplateGroupParameterSet.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.TemplateEngine.Abstractions; -using Microsoft.TemplateEngine.Utils; - -namespace Microsoft.TemplateEngine.Cli -{ - internal class TemplateGroupParameterSet : IParameterSet - { - private readonly IReadOnlyList _parameterSetList; - - private IEnumerable _parameterDefinitions; - - private IDictionary _resolvedValues; - - internal TemplateGroupParameterSet(IReadOnlyList parameterSetList) - { - _parameterSetList = parameterSetList; - } - - public IEnumerable ParameterDefinitions - { - get - { - if (_parameterDefinitions == null) - { - IDictionary combinedParams = new Dictionary(); - IDictionary> combinedChoices = new Dictionary>(); - - // gather info - foreach (IParameterSet paramSet in _parameterSetList) - { - foreach (ITemplateParameter parameter in paramSet.ParameterDefinitions) - { - // add the parameter to the combined list - if (!combinedParams.ContainsKey(parameter.Name)) - { - combinedParams.Add(parameter.Name, parameter); - } - - // build the combined choice lists - if (parameter.Choices != null) - { - Dictionary combinedChoicesForParam; - if (!combinedChoices.TryGetValue(parameter.Name, out combinedChoicesForParam)) - { - combinedChoicesForParam = new Dictionary(); - combinedChoices.Add(parameter.Name, combinedChoicesForParam); - } - - foreach (KeyValuePair choiceAndDescription in parameter.Choices) - { - if (!combinedChoicesForParam.ContainsKey(choiceAndDescription.Key)) - { - combinedChoicesForParam[choiceAndDescription.Key] = choiceAndDescription.Value; - } - } - } - } - } - - // create the combined params - IList outputParams = new List(); - foreach (KeyValuePair paramInfo in combinedParams) - { - if (!string.Equals(paramInfo.Value.DataType, "choice", StringComparison.OrdinalIgnoreCase)) - { - outputParams.Add(paramInfo.Value); - } - else - { - Dictionary choicesAndDescriptions; - if (!combinedChoices.TryGetValue(paramInfo.Key, out choicesAndDescriptions)) - { - choicesAndDescriptions = new Dictionary(); - } - - ITemplateParameter combinedParameter = new TemplateParameter( - description: paramInfo.Value.Description, - name: paramInfo.Value.Name, - priority: paramInfo.Value.Priority, - type: paramInfo.Value.Type, - isName: paramInfo.Value.IsName, - defaultValue: paramInfo.Value.DefaultValue, - datatype: paramInfo.Value.DataType, - choices: choicesAndDescriptions, - defaultIfOptionWithoutValue: paramInfo.Value.DefaultIfOptionWithoutValue); - outputParams.Add(combinedParameter); - } - } - - _parameterDefinitions = outputParams; - } - - return _parameterDefinitions; - } - } - - public IDictionary ResolvedValues - { - get - { - if (_resolvedValues == null) - { - IDictionary resolvedValues = new Dictionary(); - - foreach (ITemplateParameter groupParameter in ParameterDefinitions) - { - // take the first value from the first group that has a a value for this parameter. - foreach (IParameterSet baseParamSet in _parameterSetList) - { - ITemplateParameter baseParam = baseParamSet.ParameterDefinitions.FirstOrDefault(x => string.Equals(x.Name, groupParameter.Name, StringComparison.OrdinalIgnoreCase)); - if (baseParam != null) - { - if (baseParamSet.ResolvedValues.TryGetValue(baseParam, out object value)) - { - resolvedValues.Add(groupParameter, value); - break; // from the inner loop - } - } - } - } - - _resolvedValues = resolvedValues; - } - - return _resolvedValues; - } - } - - public bool TryGetParameterDefinition(string name, out ITemplateParameter parameter) - { - parameter = ParameterDefinitions.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - - if (parameter != null) - { - return true; - } - - parameter = new TemplateParameter( - name: name, - priority: TemplateParameterPriority.Optional, - type: "string", - datatype: "string"); - return true; - } - } -} diff --git a/src/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs b/src/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs index e91356ecacc..fa316c1f394 100644 --- a/src/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs +++ b/src/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs @@ -37,7 +37,7 @@ internal TemplateInvoker( _postActionDispatcher = new PostActionDispatcher(_environmentSettings, _callbacks, _inputGetter); } - internal async Task InvokeTemplateAsync(TemplateArgs templateArgs, CancellationToken cancellationToken) + internal async Task InvokeTemplateAsync(TemplateCommandArgs templateArgs, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -108,7 +108,7 @@ private static string GetChangeString(ChangeKind kind) }; } - private async Task CreateTemplateAsync(TemplateArgs templateArgs, CancellationToken cancellationToken) + private async Task CreateTemplateAsync(TemplateCommandArgs templateArgs, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); char[] invalidChars = Path.GetInvalidFileNameChars(); @@ -249,7 +249,7 @@ private async Task CreateTemplateAsync(TemplateArgs templateAr } } - private NewCommandStatus HandlePostActions(ITemplateCreationResult creationResult, TemplateArgs args) + private NewCommandStatus HandlePostActions(ITemplateCreationResult creationResult, TemplateCommandArgs args) { PostActionExecutionStatus result = _postActionDispatcher.Process(creationResult, args.IsDryRun, args.AllowScripts ?? AllowRunScripts.Prompt); diff --git a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.Subcommand.cs b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.Subcommand.cs index 954416f3529..89a4a1b6b7e 100644 --- a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.Subcommand.cs +++ b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.Subcommand.cs @@ -82,7 +82,7 @@ internal void Create_CanParseNameOption(string command, string? expectedValue) TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); Assert.Equal(expectedValue, templateArgs.Name); } @@ -115,7 +115,7 @@ internal void Create_CanParseTemplateOptions(string command, string parameterNam TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); if (string.IsNullOrWhiteSpace(expectedValue)) { @@ -150,7 +150,7 @@ internal void Create_CanParseChoiceTemplateOptions(string command, string parame TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); if (string.IsNullOrWhiteSpace(expectedValue)) { diff --git a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.cs b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.cs index e14de65da72..32a008e7b5f 100644 --- a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.cs +++ b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/InstantiateTests.cs @@ -264,7 +264,7 @@ internal void CanParseNameOption(string command, string? expectedValue) TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); Assert.Equal(expectedValue, templateArgs.Name); } @@ -330,7 +330,7 @@ internal void CanParseTemplateOptions(string command, string parameterName, stri TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); if (string.IsNullOrWhiteSpace(expectedValue)) { @@ -374,7 +374,7 @@ internal void CanParseChoiceTemplateOptions(string command, string parameterName TemplateCommand templateCommand = new TemplateCommand(instantiateCommand, settings, packageManager, templateGroup, templateGroup.Templates.Single()); Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - var templateArgs = new TemplateArgs(templateCommand, templateParseResult); + var templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); if (string.IsNullOrWhiteSpace(expectedValue)) { @@ -515,7 +515,7 @@ internal void DoNotAddAllowScriptOptionForTemplate() Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - TemplateArgs templateArgs = new TemplateArgs(templateCommand, templateParseResult); + TemplateCommandArgs templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); Assert.Null(templateArgs.AllowScripts); } @@ -549,7 +549,7 @@ internal void CanParseAllowScriptsOption(string command, AllowRunScripts? result Parser parser = ParserFactory.CreateParser(templateCommand); ParseResult templateParseResult = parser.Parse(args.RemainingArguments ?? Array.Empty()); - TemplateArgs templateArgs = new TemplateArgs(templateCommand, templateParseResult); + TemplateCommandArgs templateArgs = new TemplateCommandArgs(templateCommand, templateParseResult); Assert.Equal(result, templateArgs.AllowScripts); } diff --git a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/TemplateCommandTests.cs b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/TemplateCommandTests.cs index 4fc5a2778f1..c8074d5382e 100644 --- a/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/TemplateCommandTests.cs +++ b/test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/TemplateCommandTests.cs @@ -7,7 +7,6 @@ using FakeItEasy; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.Cli.Commands; -using Microsoft.TemplateEngine.Cli.Commands.Exceptions; using Microsoft.TemplateEngine.Edge; using Microsoft.TemplateEngine.Edge.Settings; using Microsoft.TemplateEngine.Mocks;