-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#1759) Add enhanced exit codes for multiple commands #2533
Conversation
e4ad497
to
99e24f4
Compare
99e24f4
to
57a7808
Compare
57a7808
to
bff97dc
Compare
bff97dc
to
636393f
Compare
636393f
to
f0edd9c
Compare
@TheCakeIsNaOH I have taken the liberty to do some fix-ups on this PR. I am also going to get some tests written to test out some of these changes, and then look to get this merged next week. Thanks for all the work that you have put into this! |
b8548e3
to
58ee7fe
Compare
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).
If enhanced exit codes are enabled, this sets the config command to exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is output).
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).
If enhanced exit codes are enabled, this sets the pin command to exit with 2 if there is nothing to do (i.e. if NOCHANGEMESSAGE is output).
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).
If enhanced exit codes are enabled, this sets the upgrade command to exit with 2 if there is nothing to do (i.e. if no packages are upgraded). This entails returning the number of successful package results from the report_action_summary method.
In other commands, when the package exit code is only available when the UseEnhancedExitCodes feature is enabled, it is marked with "(enhanced)". This was missing on this command, and this commit addresses this.
Within the following issues, a number of changes were made to allow Chocolatey CLI to exit with a ExitCode of 2, when no action was taken: chocolatey#2200 - Upgrade chocolatey#1764 - Source chocolatey#1762 - Pin chocolatey#1761 - Feature chocolatey#1760 - Config chocolatey#1759 - ApiKey This commit adds the unit tests to exercise these changes to ensure that they work as expected, and also that they continue to work as additional changes are made. No new test files have been created in this commit, but rather test were added to existing test files. The tests that have been added are a carbon copy of each other, to an extent, i.e. setup and run the required action, then assert the logs and ExitCode of 0. Then enable the UseEnhancedExitCodes feature and run the action again and assert the logs and ExitCode of 2. One change was made to the TinySpec file to ensure that the Environment.ExitCode is set to 0 (default) at the start of each test execution. This was required due to the fact that some test executions result in the ExitCode being set to 2 explicitly, but the next test didn't set it to 0, due to the fact that it relies on the default value being returned. Since this is a concern across all test executions, the decision was made to put it into the TinySpec file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@TheCakeIsNaOH thank you very much for getting all of these exit codes added! Really appreciate it! |
Description Of Changes
This adds enhanced exit codes to the
apikey
,config
,feature
,pin
,source
andupgrade
commands. Specifically, it adds exit code 2 for when there is nothing to do. All of these commands exceptupgrade
have aNOCHANGEMESSAGE
that is output, this sets exit code 2 if the conditions are met for that message to be logged, enhanced exit codes are enabled, and there is not another preexisting exit code set other than zero.The upgrade command required returning more information from a method to allow checking if no packages were outdated. The check is done by checking that there are no successes or failures.
Motivation and Context
Adding support for enhanced exit codes in more commands is useful for users that script choco, as it gives more information in a easily usable format of an exit code.
I did not try adding enhanced exit codes to push (#1763) as I don't think there is a way yet to check if the package already exists on the remote source. It would probably should be a separate PR, and perhaps a series of PRs even. (Edit, #494 would have to be completed first)
Testing
Change Types Made
Related Issue
Fixes #1759 (apikey)
Fixes #1760 (config)
Fixes #1761 (feature)
Fixes #1762 (pin)
Fixes #1764 (source)
Fixes #2200 (upgrade)
Change Checklist