public void GetParametersInvalidForTemplatesInList_NoneForAllTest() { List <ITemplateMatchInfo> matchInfo = new List <ITemplateMatchInfo>(); // template one List <MatchInfo> templateOneDispositions = new List <MatchInfo>(); templateOneDispositions.Add(new MatchInfo() { Location = MatchLocation.OtherParameter, Kind = MatchKind.InvalidParameterName, InputParameterName = "foo" }); templateOneDispositions.Add(new MatchInfo() { Location = MatchLocation.OtherParameter, Kind = MatchKind.InvalidParameterName, InputParameterName = "bar" }); ITemplateMatchInfo templateOneMatchInfo = new TemplateMatchInfo(new TemplateInfo(), templateOneDispositions); matchInfo.Add(templateOneMatchInfo); // template two List <MatchInfo> templateTwoDispositions = new List <MatchInfo>(); ITemplateMatchInfo templateTwoMatchInfo = new TemplateMatchInfo(new TemplateInfo(), templateTwoDispositions); matchInfo.Add(templateTwoMatchInfo); HelpForTemplateResolution.GetParametersInvalidForTemplatesInList(matchInfo, out IReadOnlyList <string> invalidForAllTemplates, out IReadOnlyList <string> invalidForSomeTemplates); Assert.Equal(0, invalidForAllTemplates.Count); Assert.Equal(2, invalidForSomeTemplates.Count); Assert.Contains("foo", invalidForSomeTemplates); Assert.Contains("bar", invalidForSomeTemplates); }
public async Task <CreationResultStatus> CoordinateInvocationOrAcquisitionAsync() { EnsureTemplateResolutionResult(); if (_templateToInvoke != null) { // invoke and then check for updates CreationResultStatus creationResult = await InvokeTemplateAsync(); // check for updates on this template (pack) await CheckForTemplateUpdateAsync(); return(creationResult); } else { // The command didn't resolve to an installed template. Search for something that does. bool anySearchMatches = await SearchForTemplateMatchesAsync(); if (!anySearchMatches) { return(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(_templateResolutionResult, _environment, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage)); } else { return(CreationResultStatus.Success); } } }
public void GetParametersInvalidForTemplatesInList_NoneForSomeTest() { List <ITemplateMatchInfo> matchInfo = new List <ITemplateMatchInfo>(); // template one List <MatchInfo> templateOneDispositions = new List <MatchInfo>(); templateOneDispositions.Add(new ParameterMatchInfo("foo", "test", MatchKind.InvalidName)); ITemplateMatchInfo templateOneMatchInfo = new TemplateMatchInfo(new MockTemplateInfo(), templateOneDispositions); matchInfo.Add(templateOneMatchInfo); // template two List <MatchInfo> templateTwoDispositions = new List <MatchInfo>(); templateTwoDispositions.Add(new ParameterMatchInfo("foo", "test", MatchKind.InvalidName)); ITemplateMatchInfo templateTwoMatchInfo = new TemplateMatchInfo(new MockTemplateInfo(), templateTwoDispositions); matchInfo.Add(templateTwoMatchInfo); HelpForTemplateResolution.GetParametersInvalidForTemplatesInList(matchInfo, out IReadOnlyList <string> invalidForAllTemplates, out IReadOnlyList <string> invalidForSomeTemplates); Assert.Equal(1, invalidForAllTemplates.Count); Assert.Contains("foo", invalidForAllTemplates); Assert.Equal(0, invalidForSomeTemplates.Count); }
public static bool CheckForArgsError(ITemplateMatchInfo template, out string commandParseFailureMessage) { bool argsError; if (template.HasParseError()) { commandParseFailureMessage = template.GetParseError(); argsError = true; } else { commandParseFailureMessage = null; IReadOnlyList <string> invalidParams = template.GetInvalidParameterNames(); if (invalidParams.Count > 0) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); argsError = true; } else { argsError = false; } } return(argsError); }
private async Task <CreationResultStatus> EnterTemplateManipulationFlowAsync() { if (_commandInput.IsListFlagSpecified || _commandInput.IsHelpFlagSpecified) { TemplateListResolutionResult listingTemplateResolutionResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); return(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(listingTemplateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, showUsageHelp: _commandInput.IsHelpFlagSpecified)); } TemplateResolutionResult templateResolutionResult = TemplateResolver.GetTemplateResolutionResult(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); TemplateInvocationAndAcquisitionCoordinator invocationCoordinator = new TemplateInvocationAndAcquisitionCoordinator(_settingsLoader, _commandInput, _templateCreator, _hostDataLoader, _telemetryLogger, _defaultLanguage, CommandName, _inputGetter, _callbacks); return(await invocationCoordinator.CoordinateInvocationOrAcquisitionAsync()); }
private async Task <CreationResultStatus> EnterTemplateManipulationFlowAsync() { TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches(); if (_commandInput.IsListFlagSpecified || _commandInput.IsHelpFlagSpecified) { return(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, showUsageHelp: _commandInput.IsHelpFlagSpecified)); } TemplateInvocationAndAcquisitionCoordinator invocationCoordinator = new TemplateInvocationAndAcquisitionCoordinator(_settingsLoader, _commandInput, _templateCreator, _hostDataLoader, _telemetryLogger, _defaultLanguage, CommandName, _inputGetter); return(await invocationCoordinator.CoordinateInvocationOrAcquisitionAsync()); }
internal static bool CheckForArgsError(ITemplateMatchInfo template) { bool argsError; IEnumerable <string> invalidParams = template.GetInvalidParameterNames(); if (invalidParams.Any()) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); argsError = true; } else { argsError = false; } return(argsError); }
// TODO: make sure help / usage works right in these cases. private CreationResultStatus EnterMaintenanceFlow() { if (!TemplateResolver.ValidateRemainingParameters(_commandInput, out IReadOnlyList <string> invalidParams)) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); if (_commandInput.IsHelpFlagSpecified) { // this code path doesn't go through the full help & usage stack, so needs it's own call to ShowUsageHelp(). HelpForTemplateResolution.ShowUsageHelp(_commandInput, _telemetryLogger); } else { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red()); } return(CreationResultStatus.InvalidParamValues); } if (_commandInput.ToUninstallList != null) { return(EnterUninstallFlow()); } if (_commandInput.ToInstallList != null && _commandInput.ToInstallList.Count > 0 && _commandInput.ToInstallList[0] != null) { CreationResultStatus installResult = EnterInstallFlow(); if (installResult == CreationResultStatus.Success) { _settingsLoader.Reload(); TemplateListResolutionResult resolutionResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(resolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, showUsageHelp: false); } return(installResult); } // No other cases specified, we've fallen through to "Optional usage help + List" TemplateListResolutionResult templateResolutionResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, showUsageHelp: _commandInput.IsHelpFlagSpecified); return(CreationResultStatus.Success); }
public async Task <CreationResultStatus> CoordinateInvocationOrAcquisitionAsync() { EnsureTemplateResolutionResult(); if (_templateToInvoke != null) { // invoke and then check for updates CreationResultStatus creationResult = await InvokeTemplateAsync(); // check for updates on this template (pack) await CheckForTemplateUpdateAsync(); return(creationResult); } else { ListOrHelpTemplateListResolutionResult listingTemplateListResolutionResult = TemplateListResolver.GetTemplateResolutionResultForListOrHelp(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); return(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(listingTemplateListResolutionResult, _environment, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, false)); } }
private Task <CreationResultStatus> EnterTemplateManipulationFlowAsync() { if (_commandInput.IsListFlagSpecified || _commandInput.IsHelpFlagSpecified) { TemplateListResolutionResult listingTemplateResolutionResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); return(Task.FromResult(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(listingTemplateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage, showUsageHelp: _commandInput.IsHelpFlagSpecified))); } TemplateResolutionResult templateResolutionResult = TemplateResolver.GetTemplateResolutionResult(_settingsLoader.UserTemplateCache.TemplateInfo, _hostDataLoader, _commandInput, _defaultLanguage); if (templateResolutionResult.ResolutionStatus == TemplateResolutionResult.Status.SingleMatch) { TemplateInvocationCoordinator invocationCoordinator = new TemplateInvocationCoordinator(_settingsLoader, _commandInput, _telemetryLogger, CommandName, _inputGetter, _callbacks); return(invocationCoordinator.CoordinateInvocationOrAcquisitionAsync(templateResolutionResult.TemplateToInvoke)); } else { return(Task.FromResult(HelpForTemplateResolution.CoordinateAmbiguousTemplateResolutionDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _defaultLanguage, _settingsLoader.InstallUnitDescriptorCache.Descriptors.Values))); } }
private async Task <CreationResultStatus> EnterMaintenanceFlowAsync() { if (!TemplateResolver.ValidateRemainingParameters(_commandInput, out IReadOnlyList <string> invalidParams)) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); if (_commandInput.IsHelpFlagSpecified) { // this code path doesn't go through the full help & usage stack, so needs it's own call to ShowUsageHelp(). HelpForTemplateResolution.ShowUsageHelp(_commandInput, _telemetryLogger); } else { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red()); } return(CreationResultStatus.InvalidParamValues); } // No other cases specified, we've fallen through to "Optional usage help + List" TemplateListResolutionResult templateResolutionResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp( await _settingsLoader.GetTemplatesAsync(default).ConfigureAwait(false),
private async Task <CreationResultStatus> EnterTemplateManipulationFlowAsync() { TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches(); if (_commandInput.IsListFlagSpecified || _commandInput.IsHelpFlagSpecified) { return(HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage)); } if (templateResolutionResult.TryGetUnambiguousTemplateGroupToUse(out IReadOnlyList <ITemplateMatchInfo> unambiguousTemplateGroup) && templateResolutionResult.TryGetSingularInvokableMatch(out ITemplateMatchInfo templateToInvoke) && !unambiguousTemplateGroup.Any(x => x.HasParameterMismatch()) && !unambiguousTemplateGroup.Any(x => x.HasAmbiguousParameterValueMatch())) { // If any template in the group has any ambiguous params, then don't invoke. // The check for HasAmbiguousParameterValueMatch is for an example like: // "dotnet new mvc -f netcore" // - '-f netcore' is ambiguous in the 1.x version (2 begins-with matches) // - '-f netcore' is not ambiguous in the 2.x version (1 begins-with match) return(await EnterTemplateInvocationFlowAsync(templateToInvoke).ConfigureAwait(false)); }
public void TestGetTemplateResolutionResult_OtherParameterMatch_Text() { List <ITemplateInfo> templatesToSearch = new List <ITemplateInfo>(); templatesToSearch.Add( new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T1", groupIdentity: "Console.App.Test1") .WithTag("language", "L1") .WithTag("type", "project") .WithParameters("langVersion") .WithBaselineInfo("app", "standard")); templatesToSearch.Add( new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T2", groupIdentity: "Console.App.Test2") .WithTag("language", "L2") .WithTag("type", "project") .WithParameters("test") .WithBaselineInfo("app", "standard")); templatesToSearch.Add( new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T3", groupIdentity: "Console.App.Test3") .WithTag("language", "L3") .WithTag("type", "project") .WithBaselineInfo("app", "standard")); INewCommandInput userInputs = new MockNewCommandInput("c").WithHelpOption().WithTemplateOption("langVersion"); TemplateListResolutionResult matchResult = TemplateResolver.GetTemplateResolutionResultForListOrHelp(templatesToSearch, new MockHostSpecificDataLoader(), userInputs, null); Assert.True(matchResult.HasExactMatches); Assert.Equal(1, matchResult.ExactMatchedTemplateGroups.Count); Assert.Equal(1, matchResult.ExactMatchedTemplates.Count); Assert.False(matchResult.HasLanguageMismatch); Assert.False(matchResult.HasContextMismatch); Assert.False(matchResult.HasBaselineMismatch); Assert.True(matchResult.HasUnambiguousTemplateGroup); Assert.Equal(1, matchResult.UnambiguousTemplateGroup.Count); HelpForTemplateResolution.GetParametersInvalidForTemplatesInList(matchResult.ExactMatchedTemplates, out IReadOnlyList <string> invalidForAllTemplates, out IReadOnlyList <string> invalidForSomeTemplates); Assert.Equal(0, invalidForSomeTemplates.Count); Assert.Equal(0, invalidForAllTemplates.Count); }
public static CreationResultStatus CoordinateAliasExpansion(INewCommandInput commandInput, AliasRegistry aliasRegistry, ITelemetryLogger telemetryLogger) { AliasExpansionStatus aliasExpansionStatus = AliasSupport.TryExpandAliases(commandInput, aliasRegistry); if (aliasExpansionStatus == AliasExpansionStatus.ExpansionError) { Reporter.Output.WriteLine(LocalizableStrings.AliasExpansionError); return(CreationResultStatus.InvalidParamValues); } else if (aliasExpansionStatus == AliasExpansionStatus.Expanded) { Reporter.Output.WriteLine(string.Format(LocalizableStrings.AliasCommandAfterExpansion, string.Join(" ", commandInput.Tokens))); if (commandInput.HasParseError) { Reporter.Output.WriteLine(LocalizableStrings.AliasExpandedCommandParseError); return(HelpForTemplateResolution.HandleParseError(commandInput, telemetryLogger)); } } // this is both for success and for no action. return(CreationResultStatus.Success); }
private async Task <CreationResultStatus> ExecuteAsync() { // this is checking the initial parse, which is template agnostic. if (_commandInput.HasParseError) { return(HelpForTemplateResolution.HandleParseError(_commandInput, _telemetryLogger)); } if (_commandInput.IsHelpFlagSpecified) { _telemetryLogger.TrackEvent(CommandName + TelemetryConstants.HelpEventSuffix); } if (_commandInput.ShowAliasesSpecified) { return(AliasSupport.DisplayAliasValues(EnvironmentSettings, _commandInput, _aliasRegistry, CommandName)); } if (_commandInput.ExpandedExtraArgsFiles && string.IsNullOrEmpty(_commandInput.Alias)) { // Only show this if there was no alias expansion. // ExpandedExtraArgsFiles must be checked before alias expansion - it'll get reset if there's an alias. Reporter.Output.WriteLine(string.Format(LocalizableStrings.ExtraArgsCommandAfterExpansion, string.Join(" ", _commandInput.Tokens))); } if (string.IsNullOrEmpty(_commandInput.Alias)) { // The --alias param is for creating / updating / deleting aliases. // If it's not present, try expanding aliases now. CreationResultStatus aliasExpansionResult = AliasSupport.CoordinateAliasExpansion(_commandInput, _aliasRegistry, _telemetryLogger); if (aliasExpansionResult != CreationResultStatus.Success) { return(aliasExpansionResult); } } if (!ConfigureLocale()) { return(CreationResultStatus.InvalidParamValues); } if (!Initialize()) { return(CreationResultStatus.Success); } try { bool isHiveUpdated = SyncOptionalWorkloads(); if (isHiveUpdated) { Reporter.Output.WriteLine(LocalizableStrings.OptionalWorkloadsSynchronized); } } catch (HiveSynchronizationException hiex) { Reporter.Error.WriteLine(hiex.Message.Bold().Red()); } bool forceCacheRebuild = _commandInput.HasDebuggingFlag("--debug:rebuildcache"); try { _settingsLoader.RebuildCacheFromSettingsIfNotCurrent(forceCacheRebuild); } catch (EngineInitializationException eiex) { Reporter.Error.WriteLine(eiex.Message.Bold().Red()); Reporter.Error.WriteLine(LocalizableStrings.SettingsReadError); return(CreationResultStatus.CreateFailed); } try { if (!string.IsNullOrEmpty(_commandInput.Alias) && !_commandInput.IsHelpFlagSpecified) { return(AliasSupport.ManipulateAliasIfValid(_aliasRegistry, _commandInput.Alias, _commandInput.Tokens.ToList(), AllTemplateShortNames)); } if (_commandInput.CheckForUpdates || _commandInput.CheckForUpdatesNoPrompt) { bool applyUpdates = _commandInput.CheckForUpdatesNoPrompt; CliTemplateUpdater updater = new CliTemplateUpdater(EnvironmentSettings, Installer, CommandName); bool updateCheckResult = await updater.CheckForUpdatesAsync(_settingsLoader.InstallUnitDescriptorCache.Descriptors.Values.ToList(), applyUpdates); return(updateCheckResult ? CreationResultStatus.Success : CreationResultStatus.CreateFailed); } if (_commandInput.SearchOnline) { return(await CliTemplateSearchCoordinator.SearchForTemplateMatchesAsync(EnvironmentSettings, _commandInput, _defaultLanguage).ConfigureAwait(false)); } if (string.IsNullOrWhiteSpace(TemplateName)) { return(EnterMaintenanceFlow()); } return(await EnterTemplateManipulationFlowAsync().ConfigureAwait(false)); } catch (TemplateAuthoringException tae) { Reporter.Error.WriteLine(tae.Message.Bold().Red()); return(CreationResultStatus.CreateFailed); } }
private async Task DisplayInstallResultAsync(INewCommandInput commandInput, string packageToInstall, InstallerOperationResult result, CancellationToken cancellationToken) { _ = commandInput ?? throw new ArgumentNullException(nameof(commandInput)); if (string.IsNullOrWhiteSpace(packageToInstall)) { throw new ArgumentException(nameof(packageToInstall)); } _ = result ?? throw new ArgumentNullException(nameof(result)); cancellationToken.ThrowIfCancellationRequested(); if (result.Success) { Reporter.Output.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Info_Success, result.TemplatePackage.DisplayName)); IEnumerable <ITemplateInfo> templates = await result.TemplatePackage.GetTemplates(_engineEnvironmentSettings).ConfigureAwait(false); HelpForTemplateResolution.DisplayTemplateList(templates, _engineEnvironmentSettings, commandInput, _defaultLanguage); } else { switch (result.Error) { case InstallerErrorCode.InvalidSource: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_InvalidNuGetFeeds, packageToInstall, result.ErrorMessage).Bold().Red()); break; case InstallerErrorCode.PackageNotFound: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_PackageNotFound, packageToInstall).Bold().Red()); break; case InstallerErrorCode.DownloadFailed: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_DownloadFailed, packageToInstall).Bold().Red()); break; case InstallerErrorCode.UnsupportedRequest: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_UnsupportedRequest, packageToInstall).Bold().Red()); break; case InstallerErrorCode.AlreadyInstalled: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_AlreadyInstalled, packageToInstall).Bold().Red()); break; case InstallerErrorCode.UpdateUninstallFailed: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_UninstallFailed, packageToInstall).Bold().Red()); break; case InstallerErrorCode.InvalidPackage: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_InvalidPackage, packageToInstall).Bold().Red()); break; case InstallerErrorCode.GenericError: default: Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatePackageCoordinator_lnstall_Error_GenericError, packageToInstall).Bold().Red()); break; } } }
// TODO: make sure help / usage works right in these cases. private CreationResultStatus EnterMaintenanceFlow() { if (!TemplateListResolver.ValidateRemainingParameters(_commandInput, out IReadOnlyList <string> invalidParams)) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); if (_commandInput.IsHelpFlagSpecified) { // this code path doesn't go through the full help & usage stack, so needs it's own call to ShowUsageHelp(). HelpForTemplateResolution.ShowUsageHelp(_commandInput, _telemetryLogger); } else { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red()); } return(CreationResultStatus.InvalidParamValues); } if (_commandInput.ToUninstallList != null) { if (_commandInput.ToUninstallList.Count > 0 && _commandInput.ToUninstallList[0] != null) { IEnumerable <string> failures = Installer.Uninstall(_commandInput.ToUninstallList); foreach (string failure in failures) { Console.WriteLine(LocalizableStrings.CouldntUninstall, failure); } } else { Console.WriteLine(LocalizableStrings.CommandDescription); Console.WriteLine(); Console.WriteLine(LocalizableStrings.InstalledItems); foreach (KeyValuePair <Guid, string> entry in _settingsLoader.InstallUnitDescriptorCache.InstalledItems) { Console.WriteLine($" {entry.Value}"); if (_settingsLoader.InstallUnitDescriptorCache.Descriptors.TryGetValue(entry.Value, out IInstallUnitDescriptor descriptor)) { if (descriptor.Details != null && descriptor.Details.TryGetValue("Version", out string versionValue)) { Console.WriteLine($" {LocalizableStrings.Version} {versionValue}"); } } HashSet <string> displayStrings = new HashSet <string>(StringComparer.Ordinal); foreach (TemplateInfo info in _settingsLoader.UserTemplateCache.TemplateInfo.Where(x => x.ConfigMountPointId == entry.Key)) { string str = $" {info.Name} ({info.ShortName})"; if (info.Tags != null && info.Tags.TryGetValue("language", out ICacheTag languageTag)) { str += " " + string.Join(", ", languageTag.ChoicesAndDescriptions.Select(x => x.Key)); } displayStrings.Add(str); } if (displayStrings.Count > 0) { Console.WriteLine($" {LocalizableStrings.Templates}:"); foreach (string displayString in displayStrings) { Console.WriteLine(displayString); } } } return(CreationResultStatus.Success); } } if (_commandInput.ToInstallList != null && _commandInput.ToInstallList.Count > 0 && _commandInput.ToInstallList[0] != null) { CreationResultStatus installResult = EnterInstallFlow(); if (installResult == CreationResultStatus.Success) { _settingsLoader.Reload(); TemplateListResolutionResult resolutionResult = QueryForTemplateMatches(); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(resolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage); } return(installResult); } //No other cases specified, we've fallen through to "Usage help + List" TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches(); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage); return(CreationResultStatus.Success); }
// TODO: make sure help / usage works right in these cases. private CreationResultStatus EnterMaintenanceFlow() { if (!TemplateListResolver.ValidateRemainingParameters(_commandInput, out IReadOnlyList <string> invalidParams)) { HelpForTemplateResolution.DisplayInvalidParameters(invalidParams); if (_commandInput.IsHelpFlagSpecified) { _telemetryLogger.TrackEvent(CommandName + "-Help"); HelpForTemplateResolution.ShowUsageHelp(_commandInput); } else { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red()); } return(CreationResultStatus.InvalidParamValues); } if (_commandInput.ToUninstallList != null) { if (_commandInput.ToUninstallList.Count > 0 && _commandInput.ToUninstallList[0] != null) { IEnumerable <string> failures = Installer.Uninstall(_commandInput.ToUninstallList); foreach (string failure in failures) { Console.WriteLine(LocalizableStrings.CouldntUninstall, failure); } } else { Console.WriteLine(LocalizableStrings.CommandDescription); Console.WriteLine(); Console.WriteLine(LocalizableStrings.InstalledItems); foreach (string value in _settingsLoader.InstallUnitDescriptorCache.InstalledItems.Values) { Console.WriteLine($" {value}"); } return(CreationResultStatus.Success); } } if (_commandInput.ToInstallList != null && _commandInput.ToInstallList.Count > 0 && _commandInput.ToInstallList[0] != null) { CreationResultStatus installResult = EnterInstallFlow(); if (installResult == CreationResultStatus.Success) { _settingsLoader.Reload(); TemplateListResolutionResult resolutionResult = QueryForTemplateMatches(); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(resolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage); } return(installResult); } //No other cases specified, we've fallen through to "Usage help + List" HelpForTemplateResolution.ShowUsageHelp(_commandInput); TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches(); HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage); return(CreationResultStatus.Success); }