Standard library / flag
flag.Flag
Metadata for one registered flag: Name, Usage, Value and DefValue (textual default). Expected stdout: 'n count 3 7\n'.
Formal Syntax & Structure
go syntaxgo
type Flag struct { Name string Usage string Value Value DefValue string}Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func check(e error) { if e != nil { panic(e) }}
func main() { f := flag.NewFlagSet("demo", flag.ContinueOnError) f.Int("n", 3, "count") v := f.Lookup("n") check(f.Set("n", "7")) fmt.Println(v.Name, v.Usage, v.DefValue, v.Value.String())}