Standard library / flag

flag.Lookup()

Finds registered flag metadata or nil for an unknown name. Expected stdout: '0 true\n'.

Formal Syntax & Structure

go syntaxgo
func Lookup(name string) *Flag

Parameters & Attributes

NameTypeDescription
namestringName 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")
func main() {  v := flag.Int("x", 0, "value")  _ = v  flag.Parse()  fmt.Println(flag.Lookup("x").DefValue, flag.Lookup("missing") == nil)}
Go Reference