Skip to content

Commit

Permalink
(chocolateyGH-512) Allow configuring package exit codes
Browse files Browse the repository at this point in the history
Package exit codes provide the ability for the exit code of an
underlying installer to be passed through to Chocolatey's exit code.
This value is the last non-zero exit code from a package or dependency
that Chocolatey is currently installing. This change, while
very enabling, may be surprising for some folks and they may wish to
shut this feature off.

As this feature may need to be shut off, provide it as both a feature
and switches to turn it on/off per install, upgrade, and uninstall. Add
the switches to tab expansion as well.
  • Loading branch information
ferventcoder committed Apr 25, 2016
1 parent 4b0558e commit 079b914
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ $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
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 --skip-automation-scripts --allow-multiple-versions --ignore-checksums" + $allcommands + $proInstallUpgradeOptions
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 --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --allow-multiple-versions --ignore-checksums" + $allcommands + $proInstallUpgradeOptions
pin = "--name= --version= -?" + $allcommands
outdated = "-? --source='' --user= --password=" + $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 --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums" + $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='' --skip-automation-scripts" + $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 --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums" + $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" + $allcommands
new = "--template-name= --automaticpackage --version= --maintainer='' packageversion= maintainername='' maintainerrepo='' installertype= url='' url64='' silentargs='' -?" + $allcommands
pack = "--version= -?" + $allcommands
push = "--source='' --api-key= --timeout= -?" + $allcommands
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static class Features
public static readonly string VirusCheck = "virusCheck";
public static readonly string FailOnInvalidOrMissingLicense = "failOnInvalidOrMissingLicense";
public static readonly string IgnoreInvalidOptionsSwitches = "ignoreInvalidOptionsSwitches";
public static readonly string UsePackageExitCodes = "usePackageExitCodes";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.VirusCheck = set_feature_flag(ApplicationParameters.Features.VirusCheck, configFileSettings, defaultEnabled: false, description: "Virus Check [licensed versions only] - perform virus checking on downloaded files.");
config.Features.FailOnInvalidOrMissingLicense = set_feature_flag(ApplicationParameters.Features.FailOnInvalidOrMissingLicense, configFileSettings, defaultEnabled: false, description: "Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine.");
config.Features.IgnoreInvalidOptionsSwitches = set_feature_flag(ApplicationParameters.Features.IgnoreInvalidOptionsSwitches, configFileSettings, defaultEnabled: true, description: "Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail?");
config.Features.UsePackageExitCodes = set_feature_flag(ApplicationParameters.Features.UsePackageExitCodes, configFileSettings, defaultEnabled: true, description: "Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with a 0 or a 1 (matching previous behavior). Available in 0.9.10+.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace chocolatey.infrastructure.app.commands
using commandline;
using configuration;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using services;

Expand Down Expand Up @@ -88,6 +89,19 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
{
if (option != null) configuration.Features.CheckSumFiles = false;
})
.Add("ignorepackagecodes|ignorepackageexitcodes|ignore-package-codes|ignore-package-exit-codes",
"IgnorePackageExitCodes - Exit with a 0 for success and 1 for non-success, no matter what package scripts provide for exit codes. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageExitCodes = false;
}
})
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
"UsePackageExitCodes - Package scripts can provide exit codes. Use those for choco's exit code when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option => configuration.Features.UsePackageExitCodes = option != null
)
;

//todo: Checksum / ChecksumType defaults to md5 / package name can be a url / installertype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("n|skippowershell|skip-powershell|skipscripts|skip-scripts|skip-automation-scripts",
"Skip Powershell - Do not run chocolateyUninstall.ps1. Defaults to false.",
option => configuration.SkipPackageInstallProvider = option != null)
.Add("ignorepackagecodes|ignorepackageexitcodes|ignore-package-codes|ignore-package-exit-codes",
"IgnorePackageExitCodes - Exit with a 0 for success and 1 for non-success, no matter what package scripts provide for exit codes. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageExitCodes = false;
}
})
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
"UsePackageExitCodes - Package scripts can provide exit codes. Use those for choco's exit code when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option => configuration.Features.UsePackageExitCodes = option != null
)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
{
if (option != null) configuration.Features.CheckSumFiles = false;
})
.Add("ignorepackagecodes|ignorepackageexitcodes|ignore-package-codes|ignore-package-exit-codes",
"IgnorePackageExitCodes - Exit with a 0 for success and 1 for non-success, no matter what package scripts provide for exit codes. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageExitCodes = false;
}
})
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
"UsePackageExitCodes - Package scripts can provide exit codes. Use those for choco's exit code when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
option => configuration.Features.UsePackageExitCodes = option != null
)
.Add("except=",
"Except - a comma-separated list of package names that should not be upgraded when upgrading 'all'. Defaults to empty.",
option => configuration.UpgradeCommand.PackageNamesToSkip = option.remove_surrounding_quotes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public sealed class FeaturesConfiguration
public bool VirusCheck { get; set; }
public bool FailOnInvalidOrMissingLicense { get; set; }
public bool IgnoreInvalidOptionsSwitches { get; set; }
public bool UsePackageExitCodes { get; set; }
}

//todo: retrofit other command configs this way
Expand Down

0 comments on commit 079b914

Please sign in to comment.