Skip to content
Myr

In execute(), check if command is Runnable()

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

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.

authored by Anthony Fok · committed by spf13 · parent 6e6b6a9 · Browse files · 1 file+3 added−2 removed
This commit

State

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

Diff stats

1 file+3 added−2 removed

  • other:+3 added−2 removed

1 file+3 added−2 removed

modified:command.go+3 added-2 removed
367 unmodified lines
368 c.Usage()369 r.SetOutput(out)370 return err371 } else {372 // If help is called, regardless of other flags, we print that373 if c.helpFlagVal {372 // If help is called, regardless of other flags, we print that.373 // Print help also if c.Run is nil.374 if c.helpFlagVal || !c.Runnable() {375 c.Help()376 return nil377 }378
411 unmodified lines