Skip to content

Commit 26a0460

Browse files
TheCakeIsNaOHgep13
authored andcommitted
(chocolatey#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).
1 parent 673b543 commit 26a0460

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,17 @@ Exit codes that normally result from running this command.
167167
Normal:
168168
- 0: operation was successful, no issues detected
169169
- -1 or 1: an error has occurred
170+
- 2: nothing to do, apikey already set (enhanced)
171+
172+
NOTE: Starting in v2.3.0, if you have the feature '{0}'
173+
turned on, then choco will provide enhanced exit codes that allow
174+
better integration and scripting.
170175
171176
If you find other exit codes that we have not yet documented, please
172177
file a ticket so we can document it at
173178
https://github.com/chocolatey/choco/issues/new/choose.
174179
175-
");
180+
".FormatWith(ApplicationParameters.Features.UseEnhancedExitCodes));
176181
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches");
177182
}
178183

src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs

+5
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ public void SetApiKey(ChocolateyConfiguration configuration)
396396
else
397397
{
398398
this.Log().Warn(NoChangeMessage);
399+
400+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
401+
{
402+
Environment.ExitCode = 2;
403+
}
399404
}
400405
}
401406
}

0 commit comments

Comments
 (0)