Skip to content

Conversation

@lynnemorrison
Copy link
Collaborator

@lynnemorrison lynnemorrison commented Sep 18, 2025

fixes 2135

completionCommands := []string{"completion", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd}
if len(os.Args) <= 2 || !slices.Contains(completionCommands, os.Args[1]) {
rootCmd.SetOut(os.Stderr)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For my education, could you explain what is going on here? I'm not sure I follow the logic of setting the command output stream to stderr except for completion commands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is to fix the issue that Danilo found with completion command.
skupper completion subcommand throws errors into stdout #2135

@fgiorgetti
Copy link
Member

I am not sure on the benefit of changing exclusively the output of skupper completion to stderr.

If I understand the original issue correctly, the problem reported says that on an invalid usage, the help
message is written to stdout, which is where the shell completion code is being expected.

Maybe instead of just skupper completion going to stderr, if an invalid param is also passed to
the completion command, like: skupper completion slash, the error/usage should go to stderr.

Thoughts?

Copy link
Member

@hash-d hash-d left a comment

Choose a reason for hiding this comment

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

The command still does not say what's wrong with the call, or report its error status.

I understand, however, that fixing these might take a fairly big rewrite that may not be worth it.

That said, I agree with Fernando's review, that it would be great to handle also bad arguments (and not just missing arguments). And the panic scenario needs addressed.

rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})

completionCommands := []string{"completion", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd}
if slices.Contains(completionCommands, os.Args[1]) && len(os.Args) <= 2 {
Copy link
Member

Choose a reason for hiding this comment

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

This will panic if no arguments are given (there's no os.Args[1], then)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants