diff --git a/command.go b/command.go index cbf6e24..45d14ac 100644 --- a/command.go +++ b/command.go @@ -91,6 +91,7 @@ func (c Command) Run(ctx *Context) error { if checkCommandHelp(context, c.Name) { return nil } + context.Command = c c.Action(context) return nil } diff --git a/context.go b/context.go index b469dc3..fb351b5 100644 --- a/context.go +++ b/context.go @@ -13,6 +13,7 @@ import ( // parsed command-line options. type Context struct { App *App + Command Command flagSet *flag.FlagSet globalSet *flag.FlagSet setFlags map[string]bool @@ -20,7 +21,7 @@ type Context struct { // Creates a new context. For use in when invoking an App or Command action. func NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context { - return &Context{app, set, globalSet, nil} + return &Context{App: app, flagSet: set, globalSet: globalSet} } // Looks up the value of a local int flag, returns 0 if no int flag exists diff --git a/context_test.go b/context_test.go index 75fdcd8..89041b9 100644 --- a/context_test.go +++ b/context_test.go @@ -11,9 +11,12 @@ func TestNewContext(t *testing.T) { set.Int("myflag", 12, "doc") globalSet := flag.NewFlagSet("test", 0) globalSet.Int("myflag", 42, "doc") + command := cli.Command{Name: "mycommand"} c := cli.NewContext(nil, set, globalSet) + c.Command = command expect(t, c.Int("myflag"), 12) expect(t, c.GlobalInt("myflag"), 42) + expect(t, c.Command.Name, "mycommand") } func TestContext_Int(t *testing.T) {