Skip to content
Myr

Shorter message when invalid flags provided

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

authored by spf13 · committed by spf13 · parent 55ff474 · Browse files · 2 files+1 added−7 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+1 added−7 removed

  • other:+1 added−7 removed

2 files+1 added−7 removed

modified:cobra_test.go+1 added-1 removed
199 unmodified lines
200 if e == nil {201 t.Errorf("invalid flag should generate error")202 }203204 if !strings.Contains(buf.String(), "inttwo=234") {204 if !strings.Contains(buf.String(), "unknown shorthand") {205 t.Errorf("Wrong error message displayed, \n %s", buf.String())206 }207208 if flagi2 != 99 {
86 unmodified lines
modified:command.go-6 removed
147 unmodified lines
148 cmd, a, e := c.Find(args)149 if e == nil {150 err = cmd.ParseFlags(a)151 if err != nil {152 // report flag parsing error153 c.Println(strings.Split(err.Error(), "\n")[0])154 erx := cmd.Usage()155 if erx != nil {156 return erx157 }152 return err153 } else {154 argWoFlags := cmd.Flags().Args()155 cmd.Run(cmd, argWoFlags)
260 unmodified lines