JMS #28: -h flags for subcommands

main
Jeremy Saenz 11 years ago
parent 61d5778536
commit 8cea424806

@ -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 {

@ -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)
}
}

Loading…
Cancel
Save