From 132825b2bb34d977e4ec6e9abfcaf51bdff91da9 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 20 Mar 2016 09:44:54 -0500 Subject: [PATCH] (GH-663) Search just by id Similar to #453 which searches by exact id, you should also be able to filter the search results where the filter is part of the id only. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 3 +++ .../configuration/ChocolateyConfiguration.cs | 1 + src/chocolatey/infrastructure.app/nuget/NugetList.cs | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 5487230860..a1bca53762 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -81,6 +81,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("e|exact", "Exact - Only return packages with this exact name.", option => configuration.ListCommand.Exact = option != null) + .Add("id|idonly|id-only", + "ByIdOnly - Only return packages with the filter being part of the id.", + option => configuration.ListCommand.ByIdOnly = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 929eeaba2a..f4e25a4508 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -356,6 +356,7 @@ public ListCommandConfiguration() public int? Page { get; set; } public int PageSize { get; set; } public bool Exact { get; set; } + public bool ByIdOnly { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 8b740f915b..6c844f550b 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -98,6 +98,11 @@ private static IQueryable execute_package_search(ChocolateyConfigurati results = results.Where(p => p.Id == configuration.Input); } + if (configuration.ListCommand.ByIdOnly) + { + results = results.Where(p => p.Id.Contains(configuration.Input)); + } + return results.OrderBy(p => p.Id); }