diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 3d43e5970a..a1b89ba823 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -128,6 +128,7 @@ private static ChocolateyConfiguration baseline_configuration() config.Verbose = false; config.Input = config.PackageNames = string.Empty; config.ListCommand.LocalOnly = false; + config.ListCommand.Exact = false; //config.Features.UsePowerShellHost = true; //config.Features.AutoUninstaller = true; //config.Features.CheckSumFiles = true; diff --git a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj index 4decad22d0..b8a813b35a 100644 --- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj +++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj @@ -213,6 +213,12 @@ Always + + Always + + + Always + Always @@ -400,6 +406,12 @@ Always + + Always + + + Always + Always diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/exactpackage.dontfind.nuspec b/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/exactpackage.dontfind.nuspec new file mode 100644 index 0000000000..3ad6903736 --- /dev/null +++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/exactpackage.dontfind.nuspec @@ -0,0 +1,18 @@ + + + + exactpackage.dontfind + 1.0.0 + exactpackage.dontfind + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + exactpackage.dontfind admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/tools/purpose.txt new file mode 100644 index 0000000000..ac790bf487 --- /dev/null +++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage.dontfind/1.0.0/tools/purpose.txt @@ -0,0 +1 @@ +when running choco list exactpackage -e, this package should not be returned. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/exactpackage.nuspec b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/exactpackage.nuspec new file mode 100644 index 0000000000..0b1212417c --- /dev/null +++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/exactpackage.nuspec @@ -0,0 +1,18 @@ + + + + exactpackage + 1.0.0 + exactpackage + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + exactpackage admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/tools/purpose.txt new file mode 100644 index 0000000000..ee8c252de9 --- /dev/null +++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0/tools/purpose.txt @@ -0,0 +1 @@ +when running choco list exactpackage -e, this is the only package that should be returned. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index f6289eb948..4920694b5b 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -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(); + + 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(); + } + } } } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index c290930bd4..5487230860 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -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 unparsedArguments, ChocolateyConfiguration configuration) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 43d25765d6..929eeaba2a 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -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] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index b3125d0da3..8b740f915b 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -93,6 +93,11 @@ private static IQueryable 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); }