Standard library / flag
flag.BoolVar()
Registers a flag on the default command line. Binds existing bool storage rather than returning a pointer. Boolean value; a bare -x means true, and -x=false explicitly disables it. Run with arguments: ["-x=true"]. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func BoolVar(p *bool, name string, value bool, usage string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | *bool | Pointer to storage updated during parsing. |
| name | string | Name of the flag or flag set. |
| value | bool | Default value for registration, or text to parse for Set. |
| usage | string | Help text describing the flag. |
Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func main() { var v bool; flag.BoolVar(&v, "x", false, "value"); flag.Parse(); fmt.Println(v) }