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) *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 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) }