Skip to content
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

Merged
merged 8 commits into from
Apr 23, 2024

Conversation

TheCakeIsNaOH
Copy link
Member

@TheCakeIsNaOH TheCakeIsNaOH commented Jan 17, 2022

Description Of Changes

This adds enhanced exit codes to the apikey, config, feature, pin, source and upgrade commands. Specifically, it adds exit code 2 for when there is nothing to do. All of these commands except upgrade have a NOCHANGEMESSAGE 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

.\choco.exe feature disable -n useEnhancedExitCodes
.\choco.exe apikey add --source="https://does.not.exist" --key="1234abcd"
.\choco.exe apikey add --source="https://does.not.exist" --key="1234abcd" # Should return zero
WIP - COMPLETE

.\choco.exe feature enable -n useEnhancedExitCodes
.\choco.exe apikey add --source="https://does.not.exist" --key="1234abcd" # Should return two

Change Types Made

  • Bug fix (non-breaking change)
  • Feature / Enhancement (non-breaking change)
  • Breaking change (fix or feature that could cause existing functionality to change)

Related Issue

Fixes #1759 (apikey)
Fixes #1760 (config)
Fixes #1761 (feature)
Fixes #1762 (pin)
Fixes #1764 (source)
Fixes #2200 (upgrade)

Change Checklist

  • Requires a change to the documentation
  • Documentation has been updated
  • Tests to cover my changes, have been added
  • All new and existing tests passed.
  • N/A PowerShell v2 compatibility checked.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 28.412% when pulling 57a7808 on TheCakeIsNaOH:apikey-exit-code into 6f3fc15 on chocolatey:develop.

@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review January 10, 2024 01:40
@gep13 gep13 force-pushed the apikey-exit-code branch from f0edd9c to ca2fcfa Compare April 19, 2024 13:18
@gep13
Copy link
Member

gep13 commented Apr 19, 2024

@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!

@gep13 gep13 force-pushed the apikey-exit-code branch 3 times, most recently from b8548e3 to 58ee7fe Compare April 23, 2024 12:08
TheCakeIsNaOH and others added 8 commits April 23, 2024 05:10
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.
@gep13 gep13 force-pushed the apikey-exit-code branch from 58ee7fe to 65098d1 Compare April 23, 2024 12:18
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gep13 gep13 merged commit 2596f28 into chocolatey:develop Apr 23, 2024
5 checks passed
@gep13
Copy link
Member

gep13 commented Apr 23, 2024

@TheCakeIsNaOH thank you very much for getting all of these exit codes added! Really appreciate it!

@TheCakeIsNaOH TheCakeIsNaOH deleted the apikey-exit-code branch April 26, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment