This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it
Currently, when a plugin exists with an error the CLI will print
✖ exit status 1
.However, in such a case, we shouldn't print the plugin exit code as a string but instead should use it as our own exit code.
This commit catches the fact that the error is due to a plugin exiting with error and behaves accordingly.
Furthermore, to avoid duplicating error message, this commit tells Cobra not to print final error messages since the CLI prints them itself.
Which issue(s) this PR fixes
Fixes #44
Describe testing done for PR
I first recompile the
cluster
plugin to return an exit code of 2 just for testing.Then I ran the following before applying the PR. The first command uses the
cluster
plugin while the second command uses a native CLI command, so we can compare.We can see:
exit status 2
string is printed (twice)===== errcode 1
which should be a value of 2)Then I ran the same tests with the PR applied. We can see that:
exit status 1
stringRelease note
Additional information
Special notes for your reviewer
When dealing with native commands, it is the CLI that prints the error using "github.com/aunum/log". The format is nicer as it uses colors and icons. However it prints the error to
stdout
and there does not seem to be a way to print it tostderr
. I believe such errors should go to stderr. I will open a separate issue to track this.