mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
In execute(), check if command is Runnable()
A corner case exists where c.Runnable() is not checked before c.Run() is called, thus a nil c.Run is executed leading to "panic: runtime error: invalid memory address or nil pointer dereference". This patch adds an extra c.Runnable() check in execute() to catch that corner case. Fixes #37.
This commit is contained in:
parent
6e6b6a9c19
commit
4745f1fd64
1 changed files with 3 additions and 2 deletions
|
@ -369,8 +369,9 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
r.SetOutput(out)
|
r.SetOutput(out)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
// If help is called, regardless of other flags, we print that
|
// If help is called, regardless of other flags, we print that.
|
||||||
if c.helpFlagVal {
|
// Print help also if c.Run is nil.
|
||||||
|
if c.helpFlagVal || !c.Runnable() {
|
||||||
c.Help()
|
c.Help()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue