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

Print stderr output of plugin when doing completion #827

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

marckhouzam
Copy link
Contributor

What this PR does / why we need it

A plugin, when doing shell completion, may print debug printouts to stderr. When the plugin is invoked through the tanzu cli, those printouts were being lost. This PR prints them out to stderr to allow for better troubleshooting of plugin shell completion.

Which issue(s) this PR fixes

Fixes # N/A

Describe testing done for PR

Before the PR:

# Notice that if I call the __complete command directly on the plugin, I get a debug printout "EDS query"
# This printout is on stderr
$ TANZU_BIN=tanzu TANZU_CLI_LOG_LEVEL=7 $rbac/artifacts/plugins/darwin/arm64/global/rbac/v0.0.0-dev-31f037f/tanzu-rbac-darwin_arm64 __complete role get '' > /dev/null
[i] Fetched 4 roles from EDS Query
Completion ended with directive: ShellCompDirectiveNoFileComp

# Notice here however, that if I call the __complete command on the tanzu CLI
# which will in turn call __complete on the plugin, the debug printout is not seen
$ TANZU_CLI_LOG_LEVEL=7 tanzu __complete rbac role get '' > /dev/null
Completion ended with directive: ShellCompDirectiveNoFileComp

With this PR:

# Now the debug printout is visible.
# Notice also that as a side-effect, there is a second "directive" printout;
# the first one is coming from the plugin, which was previously lost, while
# the second is the one from the CLI itself.
$ TANZU_CLI_LOG_LEVEL=7 tanzu __complete rbac role get '' > /dev/null
[i] Fetched 4 roles from EDS Query
Completion ended with directive: ShellCompDirectiveNoFileComp
Completion ended with directive: ShellCompDirectiveNoFileComp

Release note

Improve shell completion debugging by showing debug printouts.

Additional information

Special notes for your reviewer

@marckhouzam marckhouzam requested a review from a team as a code owner November 1, 2024 15:26
A plugin, when doing shell completion, may print debug printouts to
stderr.  When the plugin is invoked through the tanzu cli, those
printouts were being lost.  This commit prints them out to stderr to
allow for better troubleshooting of plugin shell completion.

Signed-off-by: Marc Khouzam <[email protected]>
Copy link
Contributor

@vuil vuil left a comment

Choose a reason for hiding this comment

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

Just want to make sure:
It felf weird initially, but the double-printing of the "Completion ended with..." looks purely cosmetic and for a command whose output is hidden no less, so change looks good. Thanks

Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this.

@marckhouzam
Copy link
Contributor Author

Just want to make sure: It felf weird initially, but the double-printing of the "Completion ended with..." looks purely cosmetic and for a command whose output is hidden no less, so change looks good. Thanks

Yes, it's a printout on stderr just meant to help a cobra-program developer debug their completion code, it is completely ignored by the completion shell script

@marckhouzam marckhouzam merged commit ef7601d into vmware-tanzu:main Nov 6, 2024
7 checks passed
@marckhouzam marckhouzam deleted the fix/compDebugMsgs branch November 6, 2024 02:48
@marckhouzam marckhouzam added this to the v1.6.0 milestone Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants