Skip to content

Commit

Permalink
(#1764) source exit 2 if nothing to do
Browse files Browse the repository at this point in the history
If enhanced exit codes are enabled, this sets the source command to
exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is
output).
  • Loading branch information
TheCakeIsNaOH committed Dec 22, 2022
1 parent db52c52 commit 862d507
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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
{
Expand Down Expand Up @@ -182,6 +187,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;
}
}
}

Expand All @@ -197,6 +207,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;
}
}
}

Expand All @@ -212,6 +227,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;
}
}
}

Expand Down

0 comments on commit 862d507

Please sign in to comment.