diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index c952e78fcd..be6e718db4 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -87,6 +87,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("id-starts-with", "IdStartsWith - Only return packages where the id starts with the search filter.", option => configuration.ListCommand.IdStartsWith = option != null) + .Add("order-by-popularity", + "OrderByPopularity - Sort by package results by popularity.", + option => configuration.ListCommand.OrderByPopularity = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 491ba1f850..d89a5e0c56 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -358,6 +358,7 @@ public ListCommandConfiguration() public bool Exact { get; set; } public bool ByIdOnly { get; set; } public bool IdStartsWith { get; set; } + public bool OrderByPopularity { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 4d7c128974..e7b39ef54b 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -114,7 +114,11 @@ private static IQueryable execute_package_search(ChocolateyConfigurati .AsQueryable(); } - return results.OrderBy(p => p.Id); + results = configuration.ListCommand.OrderByPopularity ? + results.OrderByDescending(p => p.DownloadCount).ThenBy(p => p.Id) + : results.OrderBy(p => p.Id) ; + + return results; }