Skip to content

Commit ad47ead

Browse files
committed
Merge pull request #11 from codegangsta/JMS-3
JMS #3: Passing a context struct instead of a string
2 parents 598fb19 + 96f806f commit ad47ead

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎cli.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ var Flags []Flag
2121
var Action = ShowHelp
2222

2323
func Run(args []string) {
24+
context := Context{}
2425
if len(args) > 1 {
2526
name := args[1]
2627
for _, c := range append(Commands, HelpCommand) {
2728
if c.Name == name || c.ShortName == name {
28-
c.Action(name)
29+
c.Action(context)
2930
return
3031
}
3132
}
3233
}
3334

3435
// Run default Action
35-
Action("")
36+
Action(context)
3637
}
3738

3839
type Command struct {
@@ -44,4 +45,7 @@ type Command struct {
4445
Flags flag.FlagSet
4546
}
4647

47-
type Handler func(name string)
48+
type Context struct {
49+
}
50+
51+
type Handler func(context Context)

‎help.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
HelpCommand.Action = ShowHelp
2323
}
2424

25-
func ShowHelp(name string) {
25+
func ShowHelp(c Context) {
2626
helpTemplate := `NAME:
2727
{{.Name}} - {{.Usage}}
2828
@@ -44,7 +44,7 @@ GLOBAL OPTIONS
4444
Usage,
4545
Version,
4646
append(Commands, HelpCommand),
47-
Flags,
47+
Flags,
4848
}
4949

5050
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)

0 commit comments

Comments
 (0)