Skip to content

Write Cobra deprecation messages to stderr - #5698

Merged
mislav merged 1 commit into
trunkfrom
deprecation-stderr
May 24, 2022
Merged

Write Cobra deprecation messages to stderr#5698
mislav merged 1 commit into
trunkfrom
deprecation-stderr

Conversation

@mislav

@mislav mislav commented May 23, 2022

Copy link
Copy Markdown
Contributor

We used to do the equivalent of rootCmd.SetOut(os.Stdout) because I thought that Cobra's "Out" stream represents standard output. However, upon closer inspection it turns out that this is Cobra's stream for usage errors and deprecation warnings, and those we want written to stderr as well. It is not clear to me why Cobra maintains a distinction between "Out" and "Err" streams since both seem to go to stderr by default.

This change also ceases our usage of command.Print*() functions (whose semantics are now unclear to me) in favor of explicitly writing to IOStreams.Out/ErrOut.

Fixes #5674

We used to do the equivalent of `rootCmd.SetOut(os.Stdout)` because we
thought that Cobra's "Out" stream represents standard output. However,
upon closer inspection it turns out that this is Cobra's stream for
usage errors and deprecation warnings, and those we want written to
stderr as well. It is not clear to me why Cobra maintains a distinction
between "Out" and "Err" streams since both seem to go to sdterr by
default.

This change also ceases our usage of `command.Print()` functions in
favor of explicitly writing to `IOStreams.Out/ErrOut`.
@mislav
mislav requested a review from a team as a code owner May 23, 2022 18:31
@mislav
mislav requested review from samcoe and removed request for a team May 23, 2022 18:31

@samcoe samcoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing this! Code looks good to me.

@mislav
mislav merged commit eb4439d into trunk May 24, 2022
@mislav
mislav deleted the deprecation-stderr branch May 24, 2022 10:36
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.

Flag deprecation warning should be send to stderr not stdout

3 participants