-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix stderr printing functions #894
Conversation
CC'ing @jleni |
Should https://github.com/spf13/cobra/blob/master/command.go#L926 use |
Yes, I think it should. Will amend my PR ASAP |
@amdprophet done, please review |
@alessio for some reason, the changes seem to break |
Will try to reproduce and fix shortly |
The shellcheck warnings are being addressed in #889 |
Point taken: |
3299407
to
0da6ddb
Compare
Conflicts have been resolved, please review |
Please review 🙏 |
Sorry @alessio.. but there isn't much I can do myself! I don't have any permissions in this repo |
@jharshman bump :) |
1 similar comment
@jharshman bump :) |
@jharshman Hi! Any news on this? :) |
@marckhouzam bump :) |
I'm nobody 😉 But if I may suggest something based on my experience. To help get any PR merged (in any project) you should make the review as easy as possible for the reviewer. So, in the PR description, you really need to explain what problem this fixes. If you can mention why this is valuable (the impact of the bug), it would also help prioritize this PR over the many others. Finally, mentioning if there are any backwards-compatibility issues or not would probably help build confidence in your change (that's what makes me unsure of this change, considering my limited experience with Cobra). Just my opinion though. |
I amended the PR as requested. I've just tweaked the README.me file (error messages should always go to STDERR, even when a program fails). @jharshman @marckhouzam please review again when you spare some time. Thanks for considering. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @alessio. I have run into the same issue
Thank you, this would really help us with proper output so we can use the cli tools in scripts more easily. |
I have been waiting this solution for a long time, how come is still not merged? I hope this is being merged soon. I don't know what is the problem to release this in a minor version (patch will be more accurate). Only people that upgrades will see the problem and other will update when they have bandwidth to solve the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks for waiting on this. We will get this merged very soon! 🚀
func TestCommand_Print(t *testing.T) {
errBuff, outBuff := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
wantErr := []byte("PrintErrPrintErr line\nPrintErr")
wantOut := []byte("PrintPrint line\nPrint")
root := &Command{
Run: func(cmd *Command, args []string) {
cmd.PrintErr("PrintErr")
cmd.PrintErrln("PrintErr", "line")
cmd.PrintErrf("PrintEr%s", "r")
cmd.Print("Print")
cmd.Println("Print", "line")
cmd.Printf("Prin%s", "t")
},
}
root.SetErr(errBuff)
root.SetOut(outBuff)
if err := root.Execute(); err != nil {
t.Error(err)
}
errBytes, err := ioutil.ReadAll(errBuff)
if err != nil {
t.Error(err)
}
outBytes, err := ioutil.ReadAll(outBuff)
if err != nil {
t.Error(err)
}
if !bytes.Equal(errBytes, wantErr) {
t.Errorf("got: '%s' want: '%s'", errBytes, wantErr)
}
if !bytes.Equal(outBytes, wantOut) {
t.Errorf("got: '%s' want: '%s'", outBytes, wantOut)
}
} |
Thanks: @bukowa for the patch.
@bukowa I've integrated your test case in this PR. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great - thanks so much for the patience and time spent on this. And thanks so much for adding a test case!
It now correctly prints errors to stderr (spf13/cobra#894). Signed-off-by: Matt Moyer <moyerm@vmware.com>
It now correctly prints errors to stderr (spf13/cobra#894). Signed-off-by: Matt Moyer <moyerm@vmware.com>
client/input/input.go: GetConfirmation() should communicate with the user via the io.Writer instance passed in as argument. client/keys/add.go: replace cmd.PrintErrln() calls with fmt.Fprintln(cmd.ErrOrStderr(), ...) because of cobra's PrintErr* functions broken behaviour. For more information please see spf13/cobra#894 Closes: #6601 Thanks: @noandrea for pointing this out.
since bumbping cobra version the upstream bug is now resolved spf13/cobra#894
since bumbping cobra version the upstream bug is now resolved spf13/cobra#894
since bumbping cobra version the upstream bug is now resolved spf13/cobra#894
since bumbping cobra version the upstream bug is now resolved spf13/cobra#894
since bumbping cobra version the upstream bug is now resolved spf13/cobra#894
Follow-up of #822
This fixes stderr redirection.
Closes: #1100
@spf13 @eparis