Skip to content

Commit

Permalink
(chocolateyGH-453) Adds exact filter option to choco list
Browse files Browse the repository at this point in the history
Previously there was no way to see only packages that
match exactly what you searched for. (+3 squashed commit)
  • Loading branch information
epidemicz committed Feb 25, 2016
1 parent aed7282 commit 5c36945
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
<None Include="context\dependencies\hasdependency\2.1.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\exactpackage\exactpackage.dontfind\1.0.0\exactpackage.dontfind.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\exactpackage\exactpackage\1.0.0\exactpackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\installpackage\1.0.0\installpackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -400,6 +406,12 @@
<None Include="context\upgradepackage\1.1.0\tools\graphical.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="context\exactpackage\exactpackage.dontfind\1.0.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="context\exactpackage\exactpackage\1.0.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="infrastructure\filesystem\CopyMe.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -416,7 +428,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>exactpackage.dontfind</id>
<version>1.0.0</version>
<title>exactpackage.dontfind</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>exactpackage.dontfind admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
when running choco list exactpackage -e, this package should not be returned.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>exactpackage</id>
<version>1.0.0</version>
<title>exactpackage</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>exactpackage admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
when running choco list exactpackage -e, this is the only package that should be returned.
48 changes: 48 additions & 0 deletions src/chocolatey.tests.integration/scenarios/ListScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,53 @@ public void should_not_list_any_packages()
}

}

[Concern(typeof(ChocolateyListCommand))]
public class when_searching_for_an_exact_package : ScenariosBase
{
public override void Context()
{
Configuration = Scenario.list();
Scenario.reset(Configuration);
Scenario.add_packages_to_source_location(Configuration, "exactpackage*" + Constants.PackageExtension);
Service = NUnitSetup.Container.GetInstance<IChocolateyPackageService>();

Configuration.ListCommand.Exact = true;
Configuration.Input = Configuration.PackageNames = "exactpackage";
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_contain_packages_and_versions_with_a_space_between_them()
{
MockLogger.contains_message("exactpackage 1.0.0").ShouldBeTrue();
}

[Fact]
public void should_not_contain_packages_that_do_not_match()
{
MockLogger.contains_message("exactpackage.dontfind").ShouldBeFalse();
}

[Fact]
public void should_contain_a_summary()
{
MockLogger.contains_message("packages found").ShouldBeTrue();
}

[Fact]
public void should_contain_debugging_messages()
{
MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue();
MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue();
MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue();
MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("page-size=",
"Page Size - the amount of package results to return per page. Defaults to 25.",
option => configuration.ListCommand.PageSize = int.Parse(option))
.Add("e|exact",
"Exact - Only return packages with this exact name.",
option => configuration.ListCommand.Exact = option != null)
;
//todo exact name
}

public virtual void handle_additional_argument_parsing(IList<string> unparsedArguments, ChocolateyConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public ListCommandConfiguration()
public bool IncludeRegistryPrograms { get; set; }
public int? Page { get; set; }
public int PageSize { get; set; }
public bool Exact { 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 @@ -93,6 +93,11 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati
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);
}

return results.OrderBy(p => p.Id);
}

Expand Down

0 comments on commit 5c36945

Please sign in to comment.