mirror of
https://github.com/spf13/cobra
synced 2024-11-16 10:47:09 +00:00
Remove some wonky error handling, as upstream seems correct now.
Also, it's buggy for nested commands.
This commit is contained in:
parent
f479c924b8
commit
9e7273d546
1 changed files with 17 additions and 6 deletions
15
command.go
15
command.go
|
@ -263,7 +263,11 @@ func isBooleanFlag(name string, f *flag.FlagSet) bool {
|
||||||
// Test if the named flag is a boolean flag.
|
// Test if the named flag is a boolean flag.
|
||||||
func isBooleanShortFlag(name string, f *flag.FlagSet) bool {
|
func isBooleanShortFlag(name string, f *flag.FlagSet) bool {
|
||||||
result := false
|
result := false
|
||||||
f.VisitAll(func (f *flag.Flag) { if f.Shorthand == name && f.Value.Type() == "bool" { result = true } })
|
f.VisitAll(func(f *flag.Flag) {
|
||||||
|
if f.Shorthand == name && f.Value.Type() == "bool" {
|
||||||
|
result = true
|
||||||
|
}
|
||||||
|
})
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +403,10 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.ParseFlags(a)
|
err = c.ParseFlags(a)
|
||||||
|
if err == flag.ErrHelp {
|
||||||
|
c.Help()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We're writing subcommand usage to root command's error buffer to have it displayed to the user
|
// We're writing subcommand usage to root command's error buffer to have it displayed to the user
|
||||||
r := c.Root()
|
r := c.Root()
|
||||||
|
@ -519,10 +526,14 @@ func (c *Command) Execute() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == flag.ErrHelp {
|
||||||
|
c.Help()
|
||||||
|
} else {
|
||||||
c.Println("Error:", err.Error())
|
c.Println("Error:", err.Error())
|
||||||
c.Printf("%v: invalid command %#q\n", c.Root().Name(), os.Args[1:])
|
c.Printf("%v: invalid command %#q\n", c.Root().Name(), os.Args[1:])
|
||||||
c.Printf("Run '%v help' for usage\n", c.Root().Name())
|
c.Printf("Run '%v help' for usage\n", c.Root().Name())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue