private static void ListTemplates(CommandArgument template, CommandOption source) { IEnumerable <ITemplate> results = TemplateCreator.List(template.Value, source); TableFormatter.Print(results, "(No Items)", " ", '-', new Dictionary <string, Func <ITemplate, string> > { { "Templates", x => x.Name }, { "Short Names", x => $"[{x.ShortName}]" }, { "Alias", x => AliasRegistry.GetAliasForTemplate(x) ?? "" } }); }
private static int DisplayHelp(CommandArgument template) { IReadOnlyCollection <ITemplateInfo> templates = TemplateCreator.List(template.Value); if (templates.Count > 1) { ListTemplates(template); return(-1); } ITemplateInfo tmplt = templates.First(); Reporter.Output.WriteLine(tmplt.Name); if (!string.IsNullOrWhiteSpace(tmplt.Author)) { Reporter.Output.WriteLine($"Author: {tmplt.Author}"); } if (!string.IsNullOrWhiteSpace(tmplt.Description)) { Reporter.Output.WriteLine($"Description: {tmplt.Description}"); } ITemplate realTmplt = SettingsLoader.LoadTemplate(tmplt); IParameterSet allParams = realTmplt.Generator.GetParametersForTemplate(realTmplt); Reporter.Output.WriteLine($"Parameters: {tmplt.Description}"); bool anyParams = false; foreach (ITemplateParameter parameter in allParams.ParameterDefinitions.OrderBy(x => x.Priority)) { if (parameter.Priority == TemplateParameterPriority.Implicit) { continue; } anyParams = true; Reporter.Output.WriteLine($" --{parameter.Name} ({parameter.DataType ?? "string"} - {parameter.Priority})"); Reporter.Output.WriteLine($" {parameter.Documentation}"); if (string.Equals(parameter.DataType, "choice", StringComparison.OrdinalIgnoreCase)) { Reporter.Output.WriteLine($" Allowed values:"); foreach (string choice in parameter.Choices) { Reporter.Output.WriteLine($" {choice}"); } } if (!string.IsNullOrEmpty(parameter.DefaultValue)) { Reporter.Output.WriteLine($" Default: {parameter.DefaultValue}"); } Reporter.Output.WriteLine(" "); } if (!anyParams) { Reporter.Output.WriteLine(" (No Parameters)"); } return(0); }
private static async Task <int> PerformUpdateAsync(string name, bool quiet, CommandOption source) { HashSet <IConfiguredTemplateSource> allSources = new HashSet <IConfiguredTemplateSource>(); HashSet <string> toInstall = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (ITemplate template in TemplateCreator.List(name, source)) { allSources.Add(template.Source); } foreach (IConfiguredTemplateSource src in allSources) { if (!quiet) { Reporter.Output.WriteLine($"Checking for updates for {src.Alias}..."); } bool updatesReady; if (src.ParentSource != null) { updatesReady = await src.Source.CheckForUpdatesAsync(src.ParentSource, src.Location); } else { updatesReady = await src.Source.CheckForUpdatesAsync(src.Location); } if (updatesReady) { if (!quiet) { Reporter.Output.WriteLine($"An update for {src.Alias} is available..."); } string packageId = src.ParentSource != null ? src.Source.GetInstallPackageId(src.ParentSource, src.Location) : src.Source.GetInstallPackageId(src.Location); toInstall.Add(packageId); } } if (toInstall.Count == 0) { if (!quiet) { Reporter.Output.WriteLine("No updates were found."); } return(0); } if (!quiet) { Reporter.Output.WriteLine("Installing updates..."); } List <string> installCommands = new List <string>(); List <string> uninstallCommands = new List <string>(); foreach (string packageId in toInstall) { installCommands.Add("-i"); installCommands.Add(packageId); uninstallCommands.Add("-i"); uninstallCommands.Add(packageId); } installCommands.Add("--quiet"); uninstallCommands.Add("--quiet"); Command.CreateDotNet("new3", uninstallCommands).ForwardStdOut().ForwardStdErr().Execute(); Command.CreateDotNet("new3", installCommands).ForwardStdOut().ForwardStdErr().Execute(); Broker.ComponentRegistry.ForceReinitialize(); if (!quiet) { Reporter.Output.WriteLine("Done."); } return(0); }