diff --git a/os/gcmd/gcmd_command_object.go b/os/gcmd/gcmd_command_object.go index 3158bb94c..af4282b21 100644 --- a/os/gcmd/gcmd_command_object.go +++ b/os/gcmd/gcmd_command_object.go @@ -208,7 +208,6 @@ func newCommandFromMethod(object interface{}, method reflect.Value) (command *Co // Create function that has value return. command.FuncWithValue = func(ctx context.Context, parser *Parser) (out interface{}, err error) { ctx = context.WithValue(ctx, CtxKeyParser, parser) - ctx = context.WithValue(ctx, CtxKeyCommand, command) defer func() { if exception := recover(); exception != nil { diff --git a/os/gcmd/gcmd_command_run.go b/os/gcmd/gcmd_command_run.go index 2622079b0..8cc3bbb2d 100644 --- a/os/gcmd/gcmd_command_run.go +++ b/os/gcmd/gcmd_command_run.go @@ -56,6 +56,8 @@ func (c *Command) RunWithValue(ctx context.Context) (value interface{}, err erro } func (c *Command) doRun(ctx context.Context, parser *Parser) (value interface{}, err error) { + ctx = context.WithValue(ctx, CtxKeyCommand, c) + // Check built-in help command. if parser.ContainsOpt(helpOptionName) || parser.ContainsOpt(helpOptionNameShort) { if c.HelpFunc != nil {