From 4495e2e996c7906e7724f399b1e5c6c65cdad7a0 Mon Sep 17 00:00:00 2001 From: Jeremy Saenz Date: Thu, 18 Jul 2013 19:23:00 -0700 Subject: [PATCH] JMS #4: Delegating to Command.Run --- cli.go | 4 +--- command.go | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) 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)) +}