From 1dfbc45ac865c02f012825e2b928819b1184af5a Mon Sep 17 00:00:00 2001 From: Tor Hovland Date: Sat, 15 Apr 2017 20:59:36 +0200 Subject: [PATCH] (GH-1237) Choco list/search results by id only Previously, list/search results would have id and other information, typically at least the version as well. Sometimes it makes sense to just see the id of the package. Allow for that to occur in different scenarios. --- Scenarios.md | 13 +++- .../helpers/ChocolateyTabExpansion.ps1 | 2 +- src/chocolatey.tests.integration/Scenario.cs | 1 + .../scenarios/ListScenarios.cs | 68 +++++++++++++++++++ .../commands/ChocolateyListCommand.cs | 3 + .../configuration/ChocolateyConfiguration.cs | 1 + .../services/NugetService.cs | 22 +++--- 7 files changed, 98 insertions(+), 12 deletions(-) diff --git a/Scenarios.md b/Scenarios.md index 2f388803ca..8adf82e714 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -400,7 +400,7 @@ * should not have inconclusive package result * should not have warning package result -### ChocolateyListCommand [ 8 Scenario(s), 36 Observation(s) ] +### ChocolateyListCommand [ 10 Scenario(s), 41 Observation(s) ] #### when listing local packages @@ -417,6 +417,17 @@ * should not contain packages and versions with a space between them * should only have messages related to package information +#### when listing local packages limiting output with id only + + * should contain packages id + * should not contain any version number + * should not contain pipe + +#### when listing local packages with id only + + * should contain package name + * should not contain any version number + #### when listing packages with no sources enabled * should have no sources enabled result diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index abcf287c2b..2f012675b8 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -41,7 +41,7 @@ $proNewOptions = " --file='' --build-package --file64='' --from-programs-and-fea $proUninstallOptions = " --from-programs-and-features" $commandOptions = @{ - list = "--lo --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands + list = "--lo --id-only --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands search = "--pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user= --password= --local-only --prerelease --include-programs --page= --page-size= --order-by-popularity --download-cache-only" + $allcommands info = "--pre --lo --source='' --user= --password= --local-only --prerelease" + $allcommands install = "-y -whatif -? --pre --version= --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --source='webpi' --user= --password= --prerelease --forcex86 --not-silent --package-parameters='' --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --allow-multiple-versions --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --stop-on-first-package-failure" + $proInstallUpgradeOptions + $allcommands diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 84e971aab3..b42bded2bc 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -175,6 +175,7 @@ private static ChocolateyConfiguration baseline_configuration() config.UpgradeCommand.FailOnNotInstalled = false; config.PinCommand.Name = string.Empty; config.PinCommand.Command = PinCommandType.unknown; + config.ListCommand.IdOnly = false; return config; } diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index 596730bcdc..1ca8193a04 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -289,6 +289,36 @@ public void should_contain_debugging_messages() } } + [Concern(typeof(ChocolateyListCommand))] + public class when_listing_local_packages_with_id_only : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.ListCommand.LocalOnly = true; + Configuration.ListCommand.IdOnly = true; + Configuration.Sources = ApplicationParameters.PackagesLocation; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_contain_package_name() + { + MockLogger.contains_message("upgradepackage").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_any_version_number() + { + MockLogger.contains_message(".0").ShouldBeFalse(); + } + } + [Concern(typeof(ChocolateyListCommand))] public class when_listing_local_packages_limiting_output : ScenariosBase { @@ -342,6 +372,44 @@ public void should_not_contain_debugging_messages() } } + [Concern(typeof(ChocolateyListCommand))] + public class when_listing_local_packages_limiting_output_with_id_only : ScenariosBase + { + public override void Context() + { + base.Context(); + + Configuration.ListCommand.LocalOnly = true; + Configuration.ListCommand.IdOnly = true; + Configuration.Sources = ApplicationParameters.PackagesLocation; + Configuration.RegularOutput = false; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_contain_packages_id() + { + MockLogger.contains_message("upgradepackage").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_any_version_number() + { + MockLogger.contains_message(".0").ShouldBeFalse(); + } + + [Fact] + public void should_not_contain_pipe() + { + MockLogger.contains_message("|").ShouldBeFalse(); + } + } + [Concern(typeof(ChocolateyListCommand))] public class when_listing_packages_with_no_sources_enabled : ScenariosBase { diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 80838bfb52..b21bf5dae8 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -46,6 +46,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("l|lo|localonly|local-only", "LocalOnly - Only search against local machine items.", option => configuration.ListCommand.LocalOnly = option != null) + .Add("idonly|id-only", + "Id Only - Only return Package Ids in the list results.", + option => configuration.ListCommand.IdOnly = option != null) .Add("pre|prerelease", "Prerelease - Include Prereleases? Defaults to false.", option => configuration.Prerelease = option != null) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 61c9d3db94..096b1e6a70 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -385,6 +385,7 @@ public ListCommandConfiguration() // list public bool LocalOnly { get; set; } + public bool IdOnly { get; set; } public bool IncludeRegistryPrograms { get; set; } public int? Page { get; set; } public int PageSize { get; set; } diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 5feb17407a..5772da7d1a 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -149,17 +149,19 @@ public virtual IEnumerable list_run(ChocolateyConfiguration confi if (!config.QuietOutput) { + var logger = config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal; + if (config.RegularOutput) { - this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}{2}{3}{4}".format_with( - package.Id, - package.Version.to_string(), - package.IsApproved ? " [Approved]" : string.Empty, - package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, - package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty - ) + this.Log().Info(logger, () => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".format_with( + package.Version.to_string(), + package.IsApproved ? " [Approved]" : string.Empty, + package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, + package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty + )) ); - if (config.Verbose) this.Log().Info(() => + + if (config.Verbose && !config.ListCommand.IdOnly) this.Log().Info(() => @" Title: {0} | Published: {1}{2}{3} Number of Downloads: {4} | Downloads for this version: {5} Package url @@ -203,12 +205,12 @@ Package url } else { - this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0}|{1}".format_with(package.Id, package.Version.to_string())); + this.Log().Info(logger, () => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : "|{0}".format_with(package.Version.to_string()))); } } else { - this.Log().Debug(() => "{0} {1}".format_with(package.Id, package.Version.to_string())); + this.Log().Debug(() => "{0}{1}".format_with(package.Id, config.ListCommand.IdOnly ? string.Empty : " {0}".format_with(package.Version.to_string()))); } count++;