Skip to content

Commit

Permalink
Print stderr output of plugin when doing completion (#827)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
marckhouzam authored Nov 6, 2024
1 parent 6cbbf31 commit ef7601d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/cli/plugin_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ func getCmdForPluginEx(p *PluginInfo, cmdName string, mapEntry *plugin.CommandMa
runner := NewRunner(p.Name, p.InstallationPath, completion)
ctx := context.Background()
setupPluginEnv(srcHierarchy, dstHierarchy)
output, _, err := runner.RunOutput(ctx)
output, errOutput, err := runner.RunOutput(ctx)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

// Print the stderr output from the plugin back to stderr.
// This allows for debugging printouts to be seen.
fmt.Fprint(cmd.ErrOrStderr(), errOutput)

lines := strings.Split(strings.Trim(output, "\n"), "\n")

directive := cobra.ShellCompDirectiveError
Expand Down

0 comments on commit ef7601d

Please sign in to comment.