JMS #4: Delegating to Command.Run
This commit is contained in:
parent
87d3b81d55
commit
4495e2e996
4
cli.go
4
cli.go
@ -30,9 +30,7 @@ func Run(arguments []string) {
|
||||
name := args[0]
|
||||
for _, c := range append(Commands, HelpCommand) {
|
||||
if c.Name == name || c.ShortName == name {
|
||||
locals := flagSet(c.Flags)
|
||||
locals.Parse(args[1:])
|
||||
c.Action(NewContext(locals, set))
|
||||
c.Run(context)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -8,3 +8,9 @@ type Command struct {
|
||||
Action Handler
|
||||
Flags []Flag
|
||||
}
|
||||
|
||||
func (command Command) Run(c *Context) {
|
||||
set := flagSet(command.Flags)
|
||||
set.Parse(c.Args()[1:])
|
||||
command.Action(NewContext(set, c.globalSet))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user