Skip to content

Commit

Permalink
Merge pull request #428 from RichiCoder1/feature/Paging
Browse files Browse the repository at this point in the history
(GH-427) Add paging to ListCommand
  • Loading branch information
ferventcoder committed Sep 24, 2015
2 parents 44b1f32 + 4c550a8 commit 9c430c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace chocolatey.infrastructure.app.commands
{
using System;
using System.Collections.Generic;
using System.Linq;
using attributes;
Expand Down Expand Up @@ -61,6 +62,22 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
.Add("p=|password=",
"Password - the user's password to the source. Defaults to empty.",
option => configuration.SourceCommand.Password = option.remove_surrounding_quotes())
.Add("page=",
"Page - the 'page' of results to return. Defaults to return all results.", option =>
{
int page;
if (int.TryParse(option, out page))
{
configuration.ListCommand.Page = page;
}
else
{
configuration.ListCommand.Page = null;
}
})
.Add("page-size=",
"Page Size - the amount of package results to return per page. Defaults to 25.",
option => configuration.ListCommand.PageSize = int.Parse(option))
;
//todo exact name
}
Expand Down Expand Up @@ -94,6 +111,7 @@ choco list <filter> [<options/switches>]
choco list --local-only
choco list -li
choco list -lai
choco list --page=0 --page-size=25
choco search git
choco search git -s ""https://somewhere/out/there""
choco search bob -s ""https://somewhere/protected"" -u user -p pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,16 @@ public sealed class FeaturesConfiguration
[Serializable]
public sealed class ListCommandConfiguration
{
public ListCommandConfiguration()
{
PageSize = 25;
}

// list
public bool LocalOnly { get; set; }
public bool IncludeRegistryPrograms { get; set; }
public int? Page { get; set; }
public int PageSize { get; set; }
}

[Serializable]
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configur
results = results.Where(p => p.IsLatestVersion);
}

if (configuration.ListCommand.Page.HasValue)
{
results = results.Skip(configuration.ListCommand.PageSize * configuration.ListCommand.Page.Value).Take(configuration.ListCommand.PageSize);
}

return results.OrderBy(p => p.Id)
.AsEnumerable()
.Where(PackageExtensions.IsListed)
Expand Down

0 comments on commit 9c430c0

Please sign in to comment.