From 7c7c51b0955088f4c739607daac3d6ff6a981558 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Wed, 12 Jan 2022 22:09:02 -0600 Subject: [PATCH] (#1759) apikey exit 2 if nothing to do If enhanced exit codes are enabled, this sets the apikey command to exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is output). --- .../commands/ChocolateyApiKeyCommand.cs | 7 ++++++- .../services/ChocolateyConfigSettingsService.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs index 85742f60ee..b03669066f 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs @@ -134,12 +134,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, apikey already set (enhanced) + +NOTE: Starting in v0.10.12, 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. -"); +".format_with(ApplicationParameters.Features.UseEnhancedExitCodes)); "chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches"); } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index 1058e7aff5..1a4858a67b 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -340,7 +340,15 @@ public void set_api_key(ChocolateyConfiguration configuration) _xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation); this.Log().Info(() => "Updated ApiKey for {0}".format_with(configuration.Sources)); } - else this.Log().Warn(NO_CHANGE_MESSAGE); + else + { + this.Log().Warn(NO_CHANGE_MESSAGE); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } + } } }