mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Shorter message when invalid flags provided
This commit is contained in:
parent
55ff474dee
commit
6b3d2f2e9a
2 changed files with 1 additions and 7 deletions
|
@ -201,7 +201,7 @@ func TestChildCommandFlags(t *testing.T) {
|
||||||
t.Errorf("invalid flag should generate error")
|
t.Errorf("invalid flag should generate error")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(buf.String(), "inttwo=234") {
|
if !strings.Contains(buf.String(), "unknown shorthand") {
|
||||||
t.Errorf("Wrong error message displayed, \n %s", buf.String())
|
t.Errorf("Wrong error message displayed, \n %s", buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,12 +149,6 @@ func (c *Command) execute(args []string) (err error) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
err = cmd.ParseFlags(a)
|
err = cmd.ParseFlags(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// report flag parsing error
|
|
||||||
c.Println(strings.Split(err.Error(), "\n")[0])
|
|
||||||
erx := cmd.Usage()
|
|
||||||
if erx != nil {
|
|
||||||
return erx
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
argWoFlags := cmd.Flags().Args()
|
argWoFlags := cmd.Flags().Args()
|
||||||
|
|
Loading…
Reference in a new issue