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

NameTypeDescription
p*boolPointer to storage updated during parsing.
namestringName of the flag or flag set.
valueboolDefault value for registration, or text to parse for Set.
usagestringHelp 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) }
Go Reference