// 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); }
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),
// 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); }
// 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); }