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) *boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| 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. |
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)}