mirror of
https://gitee.com/johng/gf
synced 2026-07-06 21:45:34 +08:00
improve package gcmd
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
package gcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -30,6 +31,16 @@ type Parser struct {
|
||||
commandFuncMap map[string]func() // Command function map for function handler.
|
||||
}
|
||||
|
||||
// ParserFromCtx retrieves and returns Parser from context.
|
||||
func ParserFromCtx(ctx context.Context) *Parser {
|
||||
if v := ctx.Value(CtxKeyParser); v != nil {
|
||||
if p, ok := v.(*Parser); ok {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parse creates and returns a new Parser with os.Args and supported options.
|
||||
//
|
||||
// Note that the parameter `supportedOptions` is as [option name: need argument], which means
|
||||
|
||||
Reference in New Issue
Block a user