Standard library / flag
flag.FlagSet.Lookup()
Finds registered flag metadata or nil for an unknown name. Expected stdout: '0 true\n'.
Formal Syntax & Structure
go syntaxgo
func (f *FlagSet) Lookup(name string) *FlagParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the flag or flag set. |
Return Value
*Flag
Finds registered flag metadata or nil for an unknown name.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { f := flag.NewFlagSet("demo", flag.ContinueOnError) v := f.Int("x", 0, "value") _ = v check(f.Parse(os.Args[1:])) fmt.Println(f.Lookup("x").DefValue, f.Lookup("missing") == nil)}