diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index cfb53dc1b6..808a0f3c6b 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -168,6 +168,7 @@ public static class Features public static readonly string StopOnFirstPackageFailure = "stopOnFirstPackageFailure"; public static readonly string UseRememberedArgumentsForUpgrades = "useRememberedArgumentsForUpgrades"; public static readonly string IgnoreUnfoundPackagesOnUpgradeOutdated = "ignoreUnfoundPackagesOnUpgradeOutdated"; + public static readonly string SkipPackageUpgradesWhenNotInstalled = "skipPackageUpgradesWhenNotInstalled"; public static readonly string RemovePackageInformationOnUninstall = "removePackageInformationOnUninstall"; public static readonly string LogWithoutColor = "logWithoutColor"; } diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 75d360ae5d..d45a35c2ac 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -298,6 +298,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile config.Features.StopOnFirstPackageFailure = set_feature_flag(ApplicationParameters.Features.StopOnFirstPackageFailure, configFileSettings, defaultEnabled: false, description: "Stop On First Package Failure - Stop running install, upgrade or uninstall on first package failure instead of continuing with others. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.4+."); config.Features.UseRememberedArgumentsForUpgrades = set_feature_flag(ApplicationParameters.Features.UseRememberedArgumentsForUpgrades, configFileSettings, defaultEnabled: false, description: "Use Remembered Arguments For Upgrades - When running upgrades, use arguments for upgrade that were used for installation ('remembered'). This is helpful when running upgrade for all packages. Available in 0.10.4+. This is considered in preview for 0.10.4 and will be flipped to on by default in a future release."); config.Features.IgnoreUnfoundPackagesOnUpgradeOutdated = set_feature_flag(ApplicationParameters.Features.IgnoreUnfoundPackagesOnUpgradeOutdated, configFileSettings, defaultEnabled: false, description: "Ignore Unfound Packages On Upgrade Outdated - When checking outdated or upgrades, if a package is not found against sources specified, don't report the package at all. Available in 0.10.9+."); + config.Features.SkipPackageUpgradesWhenNotInstalled = set_feature_flag(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configFileSettings, defaultEnabled: false, description: "Skip Packages Not Installed During Upgrade - if a package is not installed, do not install it during the upgrade process. Available in 0.10.12+."); config.Features.RemovePackageInformationOnUninstall = set_feature_flag(ApplicationParameters.Features.RemovePackageInformationOnUninstall, configFileSettings, defaultEnabled: false, description: "Remove Stored Package Information On Uninstall - When a package is uninstalled, should the stored package information also be removed? Available in 0.10.9+."); config.Features.LogWithoutColor = set_feature_flag(ApplicationParameters.Features.LogWithoutColor, configFileSettings, defaultEnabled: false, description: "Log without color - Do not show colorization in logging output. Available in 0.10.9+."); diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 79dcc41b0b..4a55a19894 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -165,7 +165,20 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure", "Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()), option => configuration.Features.StopOnFirstPackageFailure = option != null + ) + .Add("skip-if-not-installed|only-upgrade-installed|skip-when-not-installed", + "Skip Packages Not Installed - if a package is not installed, do not install it during the upgrade process. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()), + option => configuration.Features.SkipPackageUpgradesWhenNotInstalled = option != null ) + .Add("install-if-not-installed", + "Install Missing Packages When Not Installed - if a package is not installed, install it as part of running upgrade (typically default behavior). Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()), + option => + { + if (option != null) + { + configuration.Features.SkipPackageUpgradesWhenNotInstalled = false; + } + }) .Add("exclude-pre|exclude-prerelease|exclude-prereleases", "Exclude Prerelease - Should prerelease be ignored for upgrades? Will be ignored if you pass `--pre`. Available in 0.10.4+.", option => configuration.UpgradeCommand.ExcludePrerelease = option != null diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index bb738ea783..e50216b4d0 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -389,6 +389,7 @@ public sealed class FeaturesConfiguration public bool StopOnFirstPackageFailure { get; set; } public bool UseRememberedArgumentsForUpgrades { get; set; } public bool IgnoreUnfoundPackagesOnUpgradeOutdated { get; set; } + public bool SkipPackageUpgradesWhenNotInstalled { get; set; } public bool RemovePackageInformationOnUninstall { get; set; } //todo remove in 0.11.0 diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 4649ea7de6..5682a22540 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -634,6 +634,16 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate continue; } + if (config.Features.SkipPackageUpgradesWhenNotInstalled) + { + string warnLogMessage = "{0} is not installed and skip non-installed option selected. Skipping...".format_with(packageName); + var result = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, null, null)); + result.Messages.Add(new ResultMessage(ResultType.Warn, warnLogMessage)); + if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, warnLogMessage); + + continue; + } + string logMessage = @"{0} is not installed. Installing...".format_with(packageName); if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage);