diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs index a3e0b817a0..50dc40520e 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs @@ -165,12 +165,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 (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 a6481349a5..d356f3cf72 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -140,6 +140,11 @@ public void source_add(ChocolateyConfiguration configuration) ) { if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } else { @@ -172,6 +177,11 @@ public void source_remove(ChocolateyConfiguration configuration) else { if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } } @@ -187,6 +197,11 @@ public void source_disable(ChocolateyConfiguration configuration) else { if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } } @@ -202,6 +217,11 @@ public void source_enable(ChocolateyConfiguration configuration) else { if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE); + + if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } } }