This commit is contained in:
António Meireles 2015-10-13 22:51:40 +00:00
commit 8447c13a65
2 changed files with 14 additions and 14 deletions

View file

@ -488,8 +488,8 @@ func TestChildCommandFlags(t *testing.T) {
t.Errorf("invalid flag should generate error")
}
if !strings.Contains(r.Output, "unknown shorthand") {
t.Errorf("Wrong error message displayed, \n %s", r.Output)
if !strings.Contains(r.Error.Error(), "unknown shorthand") {
t.Errorf("Wrong error message displayed, \n %s", r.Error)
}
if flagi2 != 99 {
@ -507,8 +507,8 @@ func TestChildCommandFlags(t *testing.T) {
t.Errorf("invalid flag should generate error")
}
if !strings.Contains(r.Output, "unknown shorthand flag") {
t.Errorf("Wrong error message displayed, \n %s", r.Output)
if !strings.Contains(r.Error.Error(), "unknown shorthand flag") {
t.Errorf("Wrong error message displayed, \n %s", r.Error)
}
// Testing with persistent flag overwritten by child
@ -529,8 +529,8 @@ func TestChildCommandFlags(t *testing.T) {
t.Errorf("invalid input should generate error")
}
if !strings.Contains(r.Output, "invalid argument \"10E\" for i10E") {
t.Errorf("Wrong error message displayed, \n %s", r.Output)
if !strings.Contains(r.Error.Error(), "invalid argument \"10E\" for i10E") {
t.Errorf("Wrong error message displayed, \n %s", r.Error)
}
}
@ -547,10 +547,11 @@ func TestInvalidSubcommandFlags(t *testing.T) {
cmd.AddCommand(cmdTimes)
result := simpleTester(cmd, "times --inttwo=2 --badflag=bar")
// given that we are not checking here result.Error we check for
// stock usage message
checkResultContains(t, result, "cobra-test times [# times]")
checkResultContains(t, result, "unknown flag: --badflag")
if strings.Contains(result.Output, "unknown flag: --inttwo") {
if strings.Contains(result.Error.Error(), "unknown flag: --inttwo") {
t.Errorf("invalid --badflag flag shouldn't fail on 'unknown' --inttwo flag")
}
@ -797,7 +798,7 @@ func TestRootNoCommandHelp(t *testing.T) {
func TestRootUnknownCommand(t *testing.T) {
r := noRRSetupTest("bogus")
s := "Error: unknown command \"bogus\" for \"cobra-test\"\nRun 'cobra-test --help' for usage.\n"
s := "Run 'cobra-test --help' for usage.\n"
if r.Output != s {
t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)
@ -872,8 +873,8 @@ func TestFlagsBeforeCommand(t *testing.T) {
// With parsing error properly reported
x = fullSetupTest("-i10E echo")
if !strings.Contains(x.Output, "invalid argument \"10E\" for i10E") {
t.Errorf("Wrong error message displayed, \n %s", x.Output)
if !strings.Contains(x.Error.Error(), "invalid argument \"10E\" for i10E") {
t.Errorf("Wrong error message displayed, \n %s", x.Error)
}
//With quotes

View file

@ -626,7 +626,6 @@ func (c *Command) Execute() (err error) {
if cmd != nil {
c = cmd
}
c.Println("Error:", err.Error())
c.Printf("Run '%v --help' for usage.\n", c.CommandPath())
return err
}
@ -638,7 +637,7 @@ func (c *Command) Execute() (err error) {
return nil
}
c.Println(cmd.UsageString())
c.Println("Error:", err.Error())
return err
}
return