From 31752561838e7d2bb4624b5b524262196c702559 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Wed, 12 Jan 2022 22:17:20 -0600 Subject: [PATCH] (#1761) feature command - use exit code 2 If enhanced exit codes are enabled, this sets the feature command to exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is output). --- .../commands/ChocolateyFeatureCommand.cs | 7 ++++++- .../services/ChocolateyConfigSettingsService.cs | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs index a1c824110e..e1da018479 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs @@ -124,12 +124,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, feature already set (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, "Options and Switches"); } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index 675f56193b..4388aa33e1 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -307,6 +307,11 @@ public void DisableFeature(ChocolateyConfiguration configuration) else { this.Log().Warn(NoChangeMessage); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } } @@ -335,6 +340,11 @@ public void EnableFeature(ChocolateyConfiguration configuration) else { this.Log().Warn(NoChangeMessage); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } }