Skip to content

Commit 5c8c173

Browse files
committed
(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 a7f72e0 commit 5c8c173

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
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

+9-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,15 @@ public void SetApiKey(ChocolateyConfiguration configuration)
363363
_xmlService.Serialize(ConfigFileSettings, ApplicationParameters.GlobalConfigFileLocation);
364364
this.Log().Info(() => "Updated API key for {0}".FormatWith(configuration.Sources));
365365
}
366-
else this.Log().Warn(NoChangeMessage);
366+
else
367+
{
368+
this.Log().Warn(NoChangeMessage);
369+
370+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
371+
{
372+
Environment.ExitCode = 2;
373+
}
374+
}
367375
}
368376
}
369377

0 commit comments

Comments
 (0)