diff --git a/command.go b/command.go index a9403eb..6844855 100644 --- a/command.go +++ b/command.go @@ -10,9 +10,19 @@ type Command struct { } func (c Command) Run(ctx *Context) { + // append help to flags + c.Flags = append( + c.Flags, + helpFlag{"show help"}, + ) + set := flagSet(c.Name, c.Flags) set.Parse(ctx.Args()[1:]) - c.Action(NewContext(ctx.App, set, ctx.globalSet)) + + context := NewContext(ctx.App, set, ctx.globalSet) + checkCommandHelp(context, c.Name) + + c.Action(context) } func (c Command) HasName(name string) bool { diff --git a/help.go b/help.go index 9605818..c34d335 100644 --- a/help.go +++ b/help.go @@ -101,3 +101,10 @@ func checkHelp(c *Context) { os.Exit(0) } } + +func checkCommandHelp(c *Context, name string) { + if c.Bool("h") || c.Bool("help") { + ShowCommandHelp(c, name) + os.Exit(0) + } +}