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]
|
name := args[0]
|
||||||
for _, c := range append(Commands, HelpCommand) {
|
for _, c := range append(Commands, HelpCommand) {
|
||||||
if c.Name == name || c.ShortName == name {
|
if c.Name == name || c.ShortName == name {
|
||||||
locals := flagSet(c.Flags)
|
c.Run(context)
|
||||||
locals.Parse(args[1:])
|
|
||||||
c.Action(NewContext(locals, set))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,9 @@ type Command struct {
|
|||||||
Action Handler
|
Action Handler
|
||||||
Flags []Flag
|
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