improve package gcmd

This commit is contained in:
John Guo
2021-12-07 22:19:28 +08:00
parent 9c41f2e3f8
commit b7b71795a4
2 changed files with 2 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {