From cdd49e83446fa97711fff319f963d61476105414 Mon Sep 17 00:00:00 2001 From: Paul Hunt Date: Tue, 3 Jan 2017 17:17:11 +0000 Subject: [PATCH] (GH-994) Add ignore-pinned switch to outdated command. Previously the 'choco outdated' command listed all packages regardless of whether they were pinned or not. Add an 'ignore-pinned' switch that skips checking available upgrades for all packages that are pinned. (GH-994) Add ignore-pinned switch to outdated command. Previously the 'choco outdated' command listed all packages regardless of whether they were pinned or not. Add an 'ignore-pinned' switch that skips checking available upgrades for all packages that are pinned. --- .../helpers/ChocolateyTabExpansion.ps1 | 2 +- .../ChocolateyOutdatedCommandSpecs.cs | 7 +++++- .../commands/ChocolateyOutdatedCommand.cs | 5 +++- .../configuration/ChocolateyConfiguration.cs | 24 +++++++++++++++---- .../services/NugetService.cs | 14 +++++++---- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index e2193ffce1..f334978aa7 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -44,7 +44,7 @@ $commandOptions = @{ 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=''" + $allcommands + $proInstallUpgradeOptions pin = "--name= --version= -?" + $allcommands - outdated = "-? --source='' --user= --password=" + $allcommands + outdated = "-? --source='' --user= --password= --ignore-pinned" + $allcommands upgrade = "-y -whatif -? --pre --version= --except='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --source='webpi' --user= --password= --prerelease --forcex86 --not-silent --package-parameters='' --allow-downgrade --allow-multiple-versions --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64=''" + $allcommands + $proInstallUpgradeOptions uninstall = "-y -whatif -? --force-dependencies --remove-dependencies --all-versions --source='windowsfeatures' --source='webpi' --version= --uninstall-arguments='' --override-arguments --not-silent --params='' --package-parameters='' --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --use-autouninstaller --skip-autouninstaller --fail-on-autouninstaller --ignore-autouninstaller-failure" + $allcommands new = "--template-name= --file='Biz editions only' --automaticpackage --version= --maintainer='' packageversion= maintainername='' maintainerrepo='' installertype= url='' url64='' silentargs='' --use-built-in-template -?" + $allcommands diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs index 59dd99d5f4..bf614cf3eb 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs @@ -108,7 +108,12 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } - + + [Fact] + public void should_add_ignore_pinned_to_the_option_set() + { + optionSet.Contains("ignore-pinned").ShouldBeTrue(); + } } public class when_noop_is_called : ChocolateyOutdatedCommandSpecsBase diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs index 7c9cbe6d81..dc85315116 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.cs @@ -50,7 +50,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon option => configuration.SourceCommand.Certificate = option.remove_surrounding_quotes()) .Add("cp=|certpassword=", "Certificate Password - the client certificate's password to the source. Defaults to empty. Available in 0.9.10+.", - option => configuration.SourceCommand.CertificatePassword = option.remove_surrounding_quotes()) + option => configuration.SourceCommand.CertificatePassword = option.remove_surrounding_quotes()) + .Add("ignore-pinned", + "IgnorePinned - Ignore pinned packages. Defaults to false.", + option => configuration.OutdatedCommand.IgnorePinned = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 0af28bc32d..3b1f5538b9 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.configuration using System.Collections.Generic; using System.Reflection; using System.Text; + using commands; using domain; using logging; using platforms; @@ -46,7 +47,8 @@ public ChocolateyConfiguration() ApiKeyCommand = new ApiKeyCommandConfiguration(); PushCommand = new PushCommandConfiguration(); PinCommand = new PinCommandConfiguration(); - Proxy = new ProxyConfiguration(); + OutdatedCommand = new OutdatedCommandConfiguration(); + Proxy = new ProxyConfiguration(); #if DEBUG AllowUnofficialBuild = true; #endif @@ -111,7 +113,7 @@ private void output_tostring(StringBuilder propertyValues, IEnumerable /// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475 /// - public PinCommandConfiguration PinCommand { get; set; } - + public PinCommandConfiguration PinCommand { get; set; } + + /// + /// Configuration related specifically to Outdated command + /// + /// + /// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475 + /// + public OutdatedCommandConfiguration OutdatedCommand { get; set; } + /// /// Configuration related specifically to proxies. /// @@ -452,6 +462,12 @@ public sealed class PinCommandConfiguration public PinCommandType Command { get; set; } } + [Serializable] + public sealed class OutdatedCommandConfiguration + { + public bool IgnorePinned { get; set; } + } + [Serializable] public sealed class ApiKeyCommandConfiguration { diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index fc3b59e7bb..803f487fc9 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -578,6 +578,14 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu continue; } + var pkgInfo = _packageInfoService.get_package_information(installedPackage); + bool isPinned = pkgInfo != null && pkgInfo.IsPinned; + + if (isPinned && config.OutdatedCommand.IgnorePinned) + { + continue; + } + if (version != null && version < installedPackage.Version && !config.AllowMultipleVersions && !config.AllowDowngrade) { string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to upgrade to older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine); @@ -585,11 +593,7 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); this.Log().Error(ChocolateyLoggers.Important, logMessage); continue; - } - - var pkgInfo = _packageInfoService.get_package_information(installedPackage); - bool isPinned = pkgInfo != null && pkgInfo.IsPinned; - + } IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false); if (availablePackage == null)