Skip to content
Myr

Remove some wonky error handling, as upstream seems correct now.

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

Also, it's buggy for nested commands.

authored by Brendan Burns · committed by spf13 · parent bbdea35 · Browse files · 2 files+5 added−13 removed
This commit

State

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

Diff stats

2 files+5 added−13 removed

  • other:+5 added−13 removed

2 files+5 added−13 removed

modified:cobra_test.go+1 added-1 removed
379 unmodified lines
380 if r.Error == nil {381 t.Errorf("invalid flag should generate error")382 }383384 if !strings.Contains(r.Output, "intone=123") {384 if !strings.Contains(r.Output, "unknown shorthand flag") {385 t.Errorf("Wrong error message displayed, \n %s", r.Output)386 }387388 // Testing with persistent flag overwritten by child
215 unmodified lines
modified:command.go+4 added-12 removed
485 unmodified lines
486 e := c.ParseFlags(args)487 if e != nil {488 // Flags parsing had an error.489 // If an error happens here, we have to report it to the user490 c.Println(c.errorMsgFromParse())490 c.Println(e.Error())491 // If an error happens search also for subcommand info about that492 if c.cmdErrorBuf != nil && c.cmdErrorBuf.Len() > 0 {493 c.Println(c.cmdErrorBuf.String())494 } else {495 c.Usage()496 }497 err = e497 return e498 return499 } else {500 // If help is called, regardless of other flags, we print that501 if c.helpFlagVal {502 c.Help()
358 unmodified lines
861// Parses persistent flag tree & local flags862func (c *Command) ParseFlags(args []string) (err error) {863 c.mergePersistentFlags()864 err = c.Flags().Parse(args)864865 // The upstream library adds spaces to the error866 // response regardless of success.867 // Handling it here until fixing upstream868 if len(strings.TrimSpace(c.flagErrorBuf.String())) > 1 {869 return fmt.Errorf("%s", c.flagErrorBuf.String())870 }871872 //always return nil because upstream library is inconsistent & we always check the error buffer anyway873 return nil865 return866}867868func (c *Command) Parent() *Command {869 return c.parent
33 unmodified lines