Skip to content

Commit 4a0e218

Browse files
committed
(chocolatey#1761) feature exit 2 if nothing to do
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).
1 parent ddabfd6 commit 4a0e218

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ Exit codes that normally result from running this command.
120120
Normal:
121121
- 0: operation was successful, no issues detected
122122
- -1 or 1: an error has occurred
123+
- 2: nothing to do, feature already set (enhanced)
124+
125+
NOTE: Starting in v2.3.0, if you have the feature '{0}'
126+
turned on, then choco will provide enhanced exit codes that allow
127+
better integration and scripting.
123128
124129
If you find other exit codes that we have not yet documented, please
125130
file a ticket so we can document it at
126131
https://github.com/chocolatey/choco/issues/new/choose.
127132
128-
");
133+
".FormatWith(ApplicationParameters.Features.UseEnhancedExitCodes));
129134

130135
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches");
131136
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ public void DisableFeature(ChocolateyConfiguration configuration)
277277
else
278278
{
279279
this.Log().Warn(NoChangeMessage);
280+
281+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
282+
{
283+
Environment.ExitCode = 2;
284+
}
280285
}
281286
}
282287

@@ -305,6 +310,11 @@ public void EnableFeature(ChocolateyConfiguration configuration)
305310
else
306311
{
307312
this.Log().Warn(NoChangeMessage);
313+
314+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
315+
{
316+
Environment.ExitCode = 2;
317+
}
308318
}
309319
}
310320

0 commit comments

Comments
 (0)