diff --git a/cli.go b/cli.go index e77cc4c..32eb1de 100644 --- a/cli.go +++ b/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 } } diff --git a/command.go b/command.go index f790515..3ebb22b 100644 --- a/command.go +++ b/command.go @@ -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)) +}