Skip to content

Commit

Permalink
improve package gcmd
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Nov 24, 2021
1 parent 0db3a9f commit f91b5b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions os/gcmd/gcmd_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package gcmd

import (
"context"
"os"
"strings"

Expand All @@ -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
Expand Down

0 comments on commit f91b5b5

Please sign in to comment.