From 810fa6531673aa584b6eb7ddaf48a37f821b127d Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Wed, 12 Jan 2022 22:12:27 -0600 Subject: [PATCH] (#1760) config command - use exit code 2 If enhanced exit codes are enabled, this sets the config command to exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is output). --- .../commands/ChocolateyConfigCommand.cs | 7 ++++++- .../services/ChocolateyConfigSettingsService.cs | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs index 517807bdc7..98c860336c 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs @@ -138,12 +138,17 @@ Exit codes that normally result from running this command. Normal: - 0: operation was successful, no issues detected - -1 or 1: an error has occurred + - 2: nothing to do, config already set/unset (enhanced) + +NOTE: Starting in v2.3.0, if you have the feature '{0}' + turned on, then choco will provide enhanced exit codes that allow + better integration and scripting. If you find other exit codes that we have not yet documented, please file a ticket so we can document it at https://github.com/chocolatey/choco/issues/new/choose. -"); +".FormatWith(ApplicationParameters.Features.UseEnhancedExitCodes)); "chocolatey".Log().Info(ChocolateyLoggers.Important, "See It In Action"); "chocolatey".Log().Info(@" diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index d629df2cf8..675f56193b 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -492,6 +492,11 @@ public void SetConfig(ChocolateyConfiguration configuration) if (configuration.ConfigCommand.ConfigValue.IsEqualTo(currentValue.ToStringSafe())) { this.Log().Warn(NoChangeMessage); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } else { @@ -509,6 +514,11 @@ public void UnsetConfig(ChocolateyConfiguration configuration) if (config == null || string.IsNullOrEmpty(config.Value)) { this.Log().Warn(NoChangeMessage); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } else {