Skip to content

Commit bf83b68

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 d178a2e commit bf83b68

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
@@ -110,12 +110,17 @@ Exit codes that normally result from running this command.
110110
Normal:
111111
- 0: operation was successful, no issues detected
112112
- -1 or 1: an error has occurred
113+
- 2: nothing to do, feature already set (enhanced)
114+
115+
NOTE: Starting in v0.10.12, if you have the feature '{0}'
116+
turned on, then choco will provide enhanced exit codes that allow
117+
better integration and scripting.
113118
114119
If you find other exit codes that we have not yet documented, please
115120
file a ticket so we can document it at
116121
https://github.com/chocolatey/choco/issues/new/choose.
117122
118-
");
123+
".format_with(ApplicationParameters.Features.UseEnhancedExitCodes));
119124

120125
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches");
121126
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public void feature_disable(ChocolateyConfiguration configuration)
242242
else
243243
{
244244
this.Log().Warn(NO_CHANGE_MESSAGE);
245+
246+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
247+
{
248+
Environment.ExitCode = 2;
249+
}
245250
}
246251
}
247252

@@ -268,6 +273,11 @@ public void feature_enable(ChocolateyConfiguration configuration)
268273
else
269274
{
270275
this.Log().Warn(NO_CHANGE_MESSAGE);
276+
277+
if (configuration.Features.UseEnhancedExitCodes && Environment.ExitCode == 0)
278+
{
279+
Environment.ExitCode = 2;
280+
}
271281
}
272282
}
273283

0 commit comments

Comments
 (0)