From 96f806fd22d56957c553593239dc98f3141a25d8 Mon Sep 17 00:00:00 2001 From: Jeremy Saenz Date: Tue, 16 Jul 2013 08:11:05 -0700 Subject: [PATCH] JMS #3: Passing a context struct instead of a string --- cli.go | 10 +++++++--- help.go | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cli.go b/cli.go index a27f9dd..6c86876 100644 --- a/cli.go +++ b/cli.go @@ -21,18 +21,19 @@ var Flags []Flag var Action = ShowHelp func Run(args []string) { + context := Context{} if len(args) > 1 { name := args[1] for _, c := range append(Commands, HelpCommand) { if c.Name == name || c.ShortName == name { - c.Action(name) + c.Action(context) return } } } // Run default Action - Action("") + Action(context) } type Command struct { @@ -44,4 +45,7 @@ type Command struct { Flags flag.FlagSet } -type Handler func(name string) +type Context struct { +} + +type Handler func(context Context) diff --git a/help.go b/help.go index 4acb6fa..72a4303 100644 --- a/help.go +++ b/help.go @@ -22,7 +22,7 @@ func init() { HelpCommand.Action = ShowHelp } -func ShowHelp(name string) { +func ShowHelp(c Context) { helpTemplate := `NAME: {{.Name}} - {{.Usage}} @@ -44,7 +44,7 @@ GLOBAL OPTIONS Usage, Version, append(Commands, HelpCommand), - Flags, + Flags, } w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)