diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs index 7cce208bb8..f43a002320 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs @@ -151,6 +151,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set() optionSet.Contains("params").ShouldBeTrue(); } + [Fact] + public void should_add_applyPackageParametersToDependencies_to_the_option_set() + { + optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue(); + } + + [Fact] + public void should_add_applyInstallArgumentsToDependencies_to_the_option_set() + { + optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue(); + } + [Fact] public void should_add_allowmultipleversions_to_the_option_set() { diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs index 7a260134ea..3ebd5cce59 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs @@ -133,6 +133,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set() optionSet.Contains("params").ShouldBeTrue(); } + [Fact] + public void should_add_applyPackageParametersToDependencies_to_the_option_set() + { + optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue(); + } + + [Fact] + public void should_add_applyInstallArgumentsToDependencies_to_the_option_set() + { + optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue(); + } + [Fact] public void should_add_forcedependencies_to_the_option_set() { diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs index a1706a3d00..fad894dd9f 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs @@ -145,6 +145,18 @@ public void should_add_short_version_of_packageparameters_to_the_option_set() optionSet.Contains("params").ShouldBeTrue(); } + [Fact] + public void should_add_applyPackageParametersToDependencies_to_the_option_set() + { + optionSet.Contains("apply-package-parameters-to-dependencies").ShouldBeTrue(); + } + + [Fact] + public void should_add_applyInstallArgumentsToDependencies_to_the_option_set() + { + optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue(); + } + [Fact] public void should_add_allowmultipleversions_to_the_option_set() { diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index 18c9b162bf..fde190de50 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -62,6 +62,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=", "PackageParameters - Parameters to pass to the package. Defaults to unspecified.", option => configuration.PackageParameters = option.remove_surrounding_quotes()) + .Add("apply-install-arguments-to-dependencies", + "Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.", + option => configuration.ApplyInstallArgumentsToDependencies = option != null) + .Add("apply-package-parameters-to-dependencies", + "Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.", + option => configuration.ApplyPackageParametersToDependencies = option != null) .Add("allowdowngrade|allow-downgrade", "AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.", option => configuration.AllowDowngrade = option != null) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs index 460a90ae9d..ab2358c31c 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs @@ -58,6 +58,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=", "PackageParameters - Parameters to pass to the package. Defaults to unspecified.", option => configuration.PackageParameters = option.remove_surrounding_quotes()) + .Add("apply-install-arguments-to-dependencies", + "Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.", + option => configuration.ApplyInstallArgumentsToDependencies = option != null) + .Add("apply-package-parameters-to-dependencies", + "Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.", + option => configuration.ApplyPackageParametersToDependencies = option != null) .Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions", "AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.", option => configuration.AllowMultipleVersions = option != null) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 67fc5334ea..3c1e7402da 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -63,6 +63,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=", "PackageParameters - Parameters to pass to the package. Defaults to unspecified.", option => configuration.PackageParameters = option.remove_surrounding_quotes()) + .Add("apply-install-arguments-to-dependencies", + "Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.", + option => configuration.ApplyInstallArgumentsToDependencies = option != null) + .Add("apply-package-parameters-to-dependencies", + "Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.", + option => configuration.ApplyPackageParametersToDependencies = option != null) .Add("allowdowngrade|allow-downgrade", "AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.", option => configuration.AllowDowngrade = option != null) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index a3968ab492..7b2ec54af4 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -203,6 +203,8 @@ private void append_output(StringBuilder propertyValues, string append) public bool OverrideArguments { get; set; } public bool NotSilent { get; set; } public string PackageParameters { get; set; } + public bool ApplyPackageParametersToDependencies { get; set; } + public bool ApplyInstallArgumentsToDependencies { get; set; } public bool IgnoreDependencies { get; set; } public bool AllowMultipleVersions { get; set; } public bool AllowDowngrade { get; set; } diff --git a/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs b/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs index 95f58f137f..da5f2641ea 100644 --- a/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs @@ -40,6 +40,12 @@ public sealed class PackagesConfigFilePackageSetting [XmlAttribute(AttributeName = "packageParameters")] public string PackageParameters { get; set; } + [XmlAttribute(AttributeName = "applyPackageParametersToDependencies")] + public bool ApplyPackageParametersToDependencies { get; set; } + + [XmlAttribute(AttributeName = "applyInstallArgumentsToDependencies")] + public bool ApplyInstallArgumentsToDependencies { get; set; } + [XmlAttribute(AttributeName = "forceX86")] public bool ForceX86 { get; set; } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 0a78813ec6..323d82cb63 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -398,6 +398,8 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p if (!string.IsNullOrWhiteSpace(config.InstallArguments)) arguments.Append(" --install-arguments=\"'{0}'\"".format_with(config.InstallArguments)); if (config.OverrideArguments) arguments.Append(" --override-arguments"); if (!string.IsNullOrWhiteSpace(config.PackageParameters)) arguments.Append(" --package-parameters=\"'{0}'\"".format_with(config.PackageParameters)); + if (config.ApplyPackageParametersToDependencies) arguments.Append(" --apply-package-parameters-to-dependencies"); + if (config.ApplyInstallArgumentsToDependencies) arguments.Append(" --apply-install-arguments-to-dependencies"); if (config.AllowDowngrade) arguments.Append(" --allow-downgrade"); if (config.AllowMultipleVersions) arguments.Append(" --allow-multiple-versions"); if (config.IgnoreDependencies) arguments.Append(" --ignore-dependencies"); @@ -573,6 +575,8 @@ private IEnumerable get_packages_from_config(string pac if (pkgSettings.ForceX86) packageConfig.ForceX86 = true; if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true; if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true; + if (pkgSettings.ApplyInstallArgumentsToDependencies) packageConfig.ApplyInstallArgumentsToDependencies = true; + if (pkgSettings.ApplyPackageParametersToDependencies) packageConfig.ApplyPackageParametersToDependencies = true; this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames)); packageConfigs.Add(packageConfig); diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index ede41552f4..20fec36e3b 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -151,12 +151,14 @@ public string wrap_script_with_module(string script, ChocolateyConfiguration con private string get_script_arguments(string script, ChocolateyConfiguration config) { - return "-packageScript '{0}' -installArguments '{1}' -packageParameters '{2}'{3}{4}".format_with( + return "-packageScript '{0}' -installArguments '{1}' -packageParameters '{2}'{3}{4}{5}".format_with( script, prepare_powershell_arguments(config.InstallArguments), prepare_powershell_arguments(config.PackageParameters), config.ForceX86 ? " -forceX86" : string.Empty, - config.OverrideArguments ? " -overrideArgs" : string.Empty + config.OverrideArguments ? " -overrideArgs" : string.Empty, + config.ApplyPackageParametersToDependencies ? " -apply-package-parameters-to-dependencies" : string.Empty, + config.ApplyInstallArgumentsToDependencies ? " -apply-install-arguments-to-dependencies" : string.Empty ); } @@ -403,15 +405,13 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura // we only want to pass the following args to packages that would apply. // like choco install git -params '' should pass those params to git.install, - // but not another package - if (!package_is_a_dependency_not_a_virtual(configuration, package.Id)) + // but not another package unless the switch apply-install-arguments-to-dependencies is used + if (!package_is_a_dependency_not_a_virtual(configuration, package.Id) || configuration.ApplyInstallArgumentsToDependencies) { - this.Log().Debug(ChocolateyLoggers.Verbose, "Setting installer args and package parameters for {0}".format_with(package.Id)); + this.Log().Debug(ChocolateyLoggers.Verbose, "Setting installer args for {0}".format_with(package.Id)); Environment.SetEnvironmentVariable("installArguments", configuration.InstallArguments); Environment.SetEnvironmentVariable("installerArguments", configuration.InstallArguments); Environment.SetEnvironmentVariable("chocolateyInstallArguments", configuration.InstallArguments); - Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters); - Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters); if (configuration.OverrideArguments) { @@ -419,6 +419,15 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura } } + // we only want to pass package parameters to packages that would apply. + // but not another package unless the switch apply-package-parameters-to-dependencies is used + if (!package_is_a_dependency_not_a_virtual(configuration, package.Id) || configuration.ApplyPackageParametersToDependencies) + { + this.Log().Debug(ChocolateyLoggers.Verbose, "Setting package parameters for {0}".format_with(package.Id)); + Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters); + Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters); + } + if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksum)) { Environment.SetEnvironmentVariable("chocolateyChecksum32", configuration.DownloadChecksum);