Golang flag.FlagSet.Bool() function example

package flag

Bool defines a bool flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a bool variable that stores the value of the flag.

Golang flag.FlagSet.Bool() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {
 flagSet := flag.NewFlagSet("check", flag.ExitOnError)
 verbose := flagSet.String("verbose", "on", "Turn verbose mode on or off")

 log := flagSet.Bool("log", false, "Log is disabled by default. If true, print out the log")

 flag.Parse()

 fmt.Println(*verbose)

 fmt.Println(*log)

 }

Output :

on

false

Reference :

http://golang.org/pkg/flag/#FlagSet.Bool

Advertisement