// Displays the list of templates in a table, one row per template group. // // The columns displayed are as follows: // Except where noted, the values are taken from the highest-precedence template in the group. The info could vary among the templates in the group, but shouldn't. // (There is no check that the info doesn't vary.) // - Template Name // - Short Name: displays the first short name from the highest precedence template in the group. // - Language: All languages supported by any template in the group are displayed, with the default language in brackets, e.g.: [C#] // - Tags private static void DisplayTemplateList(IReadOnlyCollection <ITemplateMatchInfo> templates, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, string defaultLanguage) { IReadOnlyCollection <TemplateGroupTableRow> groupsForDisplay = TemplateGroupDisplay.GetTemplateGroupsForListDisplay(templates, commandInput.Language, defaultLanguage); HelpFormatter <TemplateGroupTableRow> formatter = HelpFormatter .For( environmentSettings, commandInput, groupsForDisplay, columnPadding: 2, headerSeparator: '-', blankLineBetweenRows: false) .DefineColumn(t => t.Name, LocalizableStrings.ColumnNameTemplateName, shrinkIfNeeded: true, minWidth: 15, showAlways: true) .DefineColumn(t => t.ShortName, LocalizableStrings.ColumnNameShortName, showAlways: true) .DefineColumn(t => t.Languages, out object languageColumn, LocalizableStrings.ColumnNameLanguage, NewCommandInputCli.LanguageColumnFilter, defaultColumn: true) .DefineColumn(t => t.Type, LocalizableStrings.ColumnNameType, NewCommandInputCli.TypeColumnFilter, defaultColumn: false) .DefineColumn(t => t.Author, LocalizableStrings.ColumnNameAuthor, NewCommandInputCli.AuthorColumnFilter, defaultColumn: false, shrinkIfNeeded: true, minWidth: 10) .DefineColumn(t => t.Classifications, out object tagsColumn, LocalizableStrings.ColumnNameTags, NewCommandInputCli.TagsColumnFilter, defaultColumn: true) .OrderByDescending(languageColumn, new NullOrEmptyIsLastStringComparer()) .OrderBy(tagsColumn); Reporter.Output.WriteLine(formatter.Layout()); }
/// <summary> /// Handles display for dotnet new command without parameters. /// </summary> /// <param name="args">command arguments.</param> /// <param name="cancellationToken">cancellation token.</param> /// <returns></returns> internal async Task <NewCommandStatus> DisplayCommandDescriptionAsync( GlobalArgs args, CancellationToken cancellationToken) { IEnumerable <ITemplateInfo> curatedTemplates = await GetCuratedListAsync(cancellationToken).ConfigureAwait(false); Reporter.Output.WriteLine(string.Format( LocalizableStrings.TemplateInformationCoordinator_DotnetNew_Description, Example.For <NewCommand>(args.ParseResult))); Reporter.Output.WriteLine(); Reporter.Output.WriteLine(string.Format( LocalizableStrings.TemplateInformationCoordinator_DotnetNew_TemplatesHeader, Example.For <NewCommand>(args.ParseResult))); TemplateGroupDisplay.DisplayTemplateList( _engineEnvironmentSettings, curatedTemplates, new TabularOutputSettings(_engineEnvironmentSettings.Environment), reporter: Reporter.Output); Reporter.Output.WriteLine(LocalizableStrings.TemplateInformationCoordinator_DotnetNew_ExampleHeader); Reporter.Output.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithArgument(NewCommand.ShortNameArgument, "console")); Reporter.Output.WriteLine(); Reporter.Output.WriteLine(LocalizableStrings.TemplateInformationCoordinator_DotnetNew_DisplayOptionsHint); Reporter.Output.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithArgument(NewCommand.ShortNameArgument, "console") .WithHelpOption()); Reporter.Output.WriteLine(LocalizableStrings.TemplateInformationCoordinator_DotnetNew_ListTemplatesHint); Reporter.Output.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithSubcommand <ListCommand>()); Reporter.Output.WriteLine(LocalizableStrings.TemplateInformationCoordinator_DotnetNew_SearchTemplatesHint); Reporter.Output.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithSubcommand <SearchCommand>() .WithArgument(SearchCommand.NameArgument, "web")); Reporter.Output.WriteLine(); return(NewCommandStatus.Success); }
private static IReadOnlyCollection <SearchResultTableRow> GetSearchResultsForDisplay(TemplateSourceSearchResult sourceResult, string language, string defaultLanguage) { List <SearchResultTableRow> templateGroupsForDisplay = new List <SearchResultTableRow>(); foreach (TemplatePackSearchResult packSearchResult in sourceResult.PacksWithMatches.Values) { var templateGroupsForPack = TemplateGroupDisplay.GetTemplateGroupsForListDisplay(packSearchResult.TemplateMatches, language, defaultLanguage); templateGroupsForDisplay.AddRange(templateGroupsForPack.Select(t => new SearchResultTableRow(t, packSearchResult.PackInfo.Name, packSearchResult.PackInfo.TotalDownloads))); } return(templateGroupsForDisplay); }
/// <summary> /// Handles template list display (dotnet new3 --list). /// </summary> /// <param name="args">user command input.</param> /// <param name="cancellationToken">cancellation token.</param> /// <returns></returns> internal async Task <NewCommandStatus> DisplayTemplateGroupListAsync( ListCommandArgs args, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ListTemplateResolver resolver = new ListTemplateResolver(_constraintManager, _templatePackageManager, _hostSpecificDataLoader); TemplateResolutionResult resolutionResult = await resolver.ResolveTemplatesAsync(args, _defaultLanguage, cancellationToken).ConfigureAwait(false); //IReadOnlyDictionary<string, string?>? appliedParameterMatches = resolutionResult.GetAllMatchedParametersList(); if (resolutionResult.TemplateGroupsWithMatchingTemplateInfoAndParameters.Any()) { Reporter.Output.WriteLine( string.Format( LocalizableStrings.TemplatesFoundMatchingInputParameters, GetInputParametersString(args /*, appliedParameterMatches*/))); Reporter.Output.WriteLine(); TabularOutputSettings settings = new TabularOutputSettings(_engineEnvironmentSettings.Environment, args); TemplateGroupDisplay.DisplayTemplateList( _engineEnvironmentSettings, resolutionResult.TemplateGroupsWithMatchingTemplateInfoAndParameters, settings, reporter: Reporter.Output, selectedLanguage: args.Language); return(NewCommandStatus.Success); } else { //if there is no criteria and filters it means that dotnet new list was run but there is no templates installed. if (args.ListNameCriteria == null && !args.AppliedFilters.Any()) { //No templates installed. Reporter.Output.WriteLine(LocalizableStrings.NoTemplatesFound); Reporter.Output.WriteLine(); // To search for the templates on NuGet.org, run: Reporter.Output.WriteLine(LocalizableStrings.SearchTemplatesCommand); Reporter.Output.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithSubcommand <SearchCommand>() .WithArgument(SearchCommand.NameArgument)); Reporter.Output.WriteLine(); return(NewCommandStatus.Success); } // at least one criteria was specified. // No templates found matching the following input parameter(s): {0}. Reporter.Error.WriteLine( string.Format( LocalizableStrings.NoTemplatesMatchingInputParameters, GetInputParametersString(args /*, appliedParameterMatches*/)) .Bold().Red()); if (resolutionResult.HasTemplateGroupMatches && resolutionResult.ListFilterMismatchGroupCount > 0) { // {0} template(s) partially matched, but failed on {1}. Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplatesNotValidGivenTheSpecifiedFilter, resolutionResult.ListFilterMismatchGroupCount, GetPartialMatchReason(resolutionResult, args /*, appliedParameterMatches*/)) .Bold().Red()); } if (resolutionResult.HasTemplateGroupMatches && resolutionResult.ContraintsMismatchGroupCount > 0) { // {0} template(s) are not displayed due to their constraints are not satisfied. // To display them add "--ignore-constraints" option. Reporter.Error.WriteLine( string.Format( LocalizableStrings.TemplateListCoordinator_Error_FailedConstraints, resolutionResult.ContraintsMismatchGroupCount, ListCommand.IgnoreConstraintsOption.Aliases.First()) .Bold().Red()); } Reporter.Error.WriteLine(); // To search for the templates on NuGet.org, run: Reporter.Error.WriteLine(LocalizableStrings.SearchTemplatesCommand); if (string.IsNullOrWhiteSpace(args.ListNameCriteria)) { Reporter.Error.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithSubcommand <SearchCommand>() .WithArgument(SearchCommand.NameArgument)); } else { Reporter.Error.WriteCommand( Example .For <NewCommand>(args.ParseResult) .WithSubcommand <SearchCommand>() .WithArgument(SearchCommand.NameArgument, args.ListNameCriteria)); } Reporter.Error.WriteLine(); return(NewCommandStatus.NotFound); } }
internal static void DisplayTemplateList(IEnumerable <ITemplateInfo> templates, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, string defaultLanguage, bool useErrorOutput = false) { IReadOnlyCollection <TemplateGroupTableRow> groupsForDisplay = TemplateGroupDisplay.GetTemplateGroupsForListDisplay(templates, commandInput.Language, defaultLanguage); DisplayTemplateList(groupsForDisplay, environmentSettings, commandInput, useErrorOutput); }