internal static Func <TemplatePackageSearchData, IReadOnlyList <ITemplateInfo> > GetMatchingTemplatesFilter(SearchCommandArgs commandArgs)
        {
            return((templatePackageSearchData) =>
            {
                InMemoryHostSpecificDataLoader hostDataLoader = new InMemoryHostSpecificDataLoader(templatePackageSearchData);
                IEnumerable <TemplateSearchData> templates = templatePackageSearchData.Templates.Where(template => IsNotHiddenBySearchFile(template));
                IEnumerable <TemplateGroup> templateGroups = TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templates, hostDataLoader));
                IEnumerable <Func <TemplateGroup, MatchInfo?> > groupFilters = new[]
                {
                    CliFilters.NameTemplateGroupFilter(commandArgs.SearchNameCriteria)
                };

                IEnumerable <Func <ITemplateInfo, MatchInfo?> > templateFilters =
                    commandArgs.AppliedFilters
                    .OfType <TemplateFilterOptionDefinition>()
                    .Select(filter => filter.TemplateMatchFilter(commandArgs.GetFilterValue(filter)));

                IEnumerable <TemplateGroupMatchInfo> matchInformation =
                    templateGroups.Select(
                        group =>
                        TemplateGroupMatchInfo.ApplyFilters(
                            group,
                            groupFilters,
                            templateFilters,
                            //TODO: implement it for template options matching, for now the filter just returns empty collection.
                            CliFilters.EmptyTemplateParameterFilter()));

                return matchInformation
                .Where(group => group.IsGroupAndTemplateInfoAndParametersMatch)
                .SelectMany(group => group.TemplatesWithMatchingParameters)
                .ToList();
            });
        }
 internal Func <TemplatePackageSearchData, bool> GetPackFilter(SearchCommandArgs commandArgs)
 {
     return(templatePackageSearchData =>
     {
         return AlreadyInstalledFilter(templatePackageSearchData) &&
         commandArgs.AppliedFilters
         .OfType <PackageFilterOptionDefinition>()
         .All(filter => filter.PackageMatchFilter(commandArgs.GetFilterValue(filter))(templatePackageSearchData));
     });
 }
Exemple #3
0
        public void Search_CanParseFilterOptionWithoutMainCriteria(string command, string expectedFilter)
        {
            FilterOptionDefinition expectedDef = _stringToFilterDefMap[expectedFilter];

            ITemplateEngineHost host      = TestHost.GetVirtualHost(additionalComponents: BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false));
            NewCommand          myCommand = (NewCommand)NewCommandFactory.Create("new", _ => host, _ => new TelemetryLogger(null, false), new NewCommandCallbacks());

            var parseResult        = myCommand.Parse(command);
            SearchCommandArgs args = new SearchCommandArgs((BaseSearchCommand)parseResult.CommandResult.Command, parseResult);

            Assert.Single(args.AppliedFilters);
            Assert.Contains("filter-value", args.GetFilterValue(expectedDef));
            Assert.Null(args.SearchNameCriteria);
        }