Standard library / flag

flag.FlagSet.Bool()

Registers a flag on an independent FlagSet. 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 (f *FlagSet) 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 an independent FlagSet.

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  f := flag.NewFlagSet("demo", flag.ContinueOnError)  v := f.Bool("x", false, "value")  check(f.Parse(os.Args[1:]))  fmt.Println(*v)}
Go Reference