urfave-cli/command.go

31 lines
559 B
Go
Raw Normal View History

package cli
type Command struct {
Name string
ShortName string
Usage string
Description string
2013-07-20 22:50:13 +00:00
Action func(context *Context)
Flags []Flag
}
2013-07-19 02:23:00 +00:00
2013-07-20 15:21:20 +00:00
func (c Command) Run(ctx *Context) {
2013-08-14 04:40:39 +00:00
// append help to flags
c.Flags = append(
c.Flags,
helpFlag{"show help"},
)
2013-07-20 15:21:20 +00:00
set := flagSet(c.Name, c.Flags)
set.Parse(ctx.Args()[1:])
2013-08-14 04:40:39 +00:00
context := NewContext(ctx.App, set, ctx.globalSet)
checkCommandHelp(context, c.Name)
c.Action(context)
2013-07-19 02:23:00 +00:00
}
2013-07-19 02:30:18 +00:00
2013-07-20 15:21:20 +00:00
func (c Command) HasName(name string) bool {
return c.Name == name || c.ShortName == name
2013-07-19 02:30:18 +00:00
}