diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index a1bca53762..c952e78fcd 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -81,9 +81,12 @@ 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.", + .Add("by-id-only", + "ByIdOnly - Only return packages where the id contains the search filter.", option => configuration.ListCommand.ByIdOnly = option != null) + .Add("id-starts-with", + "IdStartsWith - Only return packages where the id starts with the search filter.", + option => configuration.ListCommand.IdStartsWith = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index f4e25a4508..491ba1f850 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -357,6 +357,7 @@ public ListCommandConfiguration() public int PageSize { get; set; } public bool Exact { get; set; } public bool ByIdOnly { get; set; } + public bool IdStartsWith { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 6c844f550b..4d7c128974 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -15,6 +15,7 @@ namespace chocolatey.infrastructure.app.nuget { + using System; using System.Collections.Generic; using System.Linq; @@ -57,6 +58,31 @@ private static IQueryable execute_package_search(ChocolateyConfigurati IQueryable results = packageRepository.Search(configuration.Input, configuration.Prerelease); + + if (configuration.ListCommand.Page.HasValue) + { + results = results.Skip(configuration.ListCommand.PageSize * configuration.ListCommand.Page.Value).Take(configuration.ListCommand.PageSize); + } + + if (configuration.ListCommand.Exact) + { + results = results.Where(p => p.Id == configuration.Input); + } + + if (configuration.ListCommand.ByIdOnly) + { + results = isRemote ? + results.Where(p => p.Id.Contains(configuration.Input)) + : results.Where(p => p.Id.contains(configuration.Input, StringComparison.OrdinalIgnoreCase)); + } + + if (configuration.ListCommand.IdStartsWith) + { + results = isRemote ? + results.Where(p => p.Id.StartsWith(configuration.Input)) + : results.Where(p => p.Id.StartsWith(configuration.Input, StringComparison.OrdinalIgnoreCase)); + } + if (configuration.AllVersions) { if (isRemote) @@ -88,21 +114,6 @@ private static IQueryable execute_package_search(ChocolateyConfigurati .AsQueryable(); } - if (configuration.ListCommand.Page.HasValue) - { - results = results.Skip(configuration.ListCommand.PageSize * configuration.ListCommand.Page.Value).Take(configuration.ListCommand.PageSize); - } - - if (configuration.ListCommand.Exact) - { - 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); }