Standard library / flag

flag.Bool()

Registers a flag on the default command line. 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 Bool(name string, value bool, usage string) *bool

Parameters & Attributes

NameTypeDescription
namestringName of the flag or flag set.
valueboolDefault value for registration, or text to parse for Set.
usagestringHelp text describing the flag.

Return Value

*bool

Registers a flag on the default command line.

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt")
func main() { v := flag.Bool("x", false, "value"); flag.Parse(); fmt.Println(*v) }
Go Reference