From f7825f4104913db7d6fef0db691f9d6ad72bcad0 Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Thu, 11 Dec 2014 10:06:11 -0700 Subject: [PATCH] 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. --- command.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/command.go b/command.go index b506b1ed..770dda10 100644 --- a/command.go +++ b/command.go @@ -357,8 +357,9 @@ func (c *Command) execute(a []string) (err error) { if err != nil { return err } else { - // If help is called, regardless of other flags, we print that - if c.helpFlagVal { + // If help is called, regardless of other flags, we print that. + // Print help also if c.Run is nil. + if c.helpFlagVal || !c.Runnable() { c.Help() return nil }