mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Fixing error messaging when upstream flag library is inconsistent.
This commit is contained in:
parent
2f19d3c266
commit
fae133554d
1 changed files with 4 additions and 3 deletions
|
@ -265,6 +265,7 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.ParseFlags(a)
|
err = c.ParseFlags(a)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
@ -574,15 +575,15 @@ func (c *Command) ParseFlags(args []string) (err error) {
|
||||||
c.mergePersistentFlags()
|
c.mergePersistentFlags()
|
||||||
|
|
||||||
err = c.Flags().Parse(args)
|
err = c.Flags().Parse(args)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// The upstream library adds spaces to the error
|
// The upstream library adds spaces to the error
|
||||||
// response regardless of success.
|
// response regardless of success.
|
||||||
// Handling it here until fixing upstream
|
// Handling it here until fixing upstream
|
||||||
if len(strings.TrimSpace(c.flagErrorBuf.String())) > 1 {
|
if len(strings.TrimSpace(c.flagErrorBuf.String())) > 1 {
|
||||||
return fmt.Errorf("%s", c.flagErrorBuf.String())
|
return fmt.Errorf("%s", c.flagErrorBuf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//always return nil because upstream library is inconsistent & we always check the error buffer anyway
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue