Skip to content
Myr

Subcommands flag parsing errors print subcommand usage and not root's command usage

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Conflicts: command.go

authored by Maciej Szulik · committed by spf13 · parent 1cb3160 · Browse files · 1 file+9 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−5 removed

  • other:+9 added−5 removed

1 file+9 added−5 removed

modified:command.go+9 added-5 removed
355 unmodified lines
356 err = c.ParseFlags(a)357358 if err != nil {359 // We're writing subcommand usage to root command's error buffer to have it displayed to the user360 r := c.Root()360 if c.Root().cmdErrorBuf == nil {361 c.Root().cmdErrorBuf = new(bytes.Buffer)361 if r.cmdErrorBuf == nil {362 r.cmdErrorBuf = new(bytes.Buffer)363 }364 // for writing the usage to the buffer we need to switch the output temporarily365 // since Out() returns root output, you also need to revert that on root364 out := c.Out()365 c.SetOutput(c.Root().cmdErrorBuf)366 out := r.Out()367 r.SetOutput(r.cmdErrorBuf)368 c.Usage()367 c.SetOutput(out)369 r.SetOutput(out)370 return err371 } else {372 // If help is called, regardless of other flags, we print that373 if c.helpFlagVal {
126 unmodified lines
500// Used for testing501func (c *Command) ResetCommands() {502 c.commands = nil503 c.helpCommand = nil504 c.cmdErrorBuf = new(bytes.Buffer)505 c.cmdErrorBuf.Reset()506}507508func (c *Command) Commands() []*Command {509 return c.commands
279 unmodified lines