Golang flag.FlagSet.BoolVar() function example

package flag

BoolVar defines a bool flag with specified name(2nd parameter), default value(3rd parameter), and usage string(4th parameter). The argument p(1st parameter) points to a bool variable in which to store the value of the flag.

Golang flag.FlagSet.BoolVar() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

 var tocheck bool

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

 flagSet.BoolVar(&tocheck, "diskspace", true, "check empty diskspace. Default is true")

 flag.Parse()

 fmt.Println(tocheck)

 fmt.Println(*log)

 }

Output :

true

false

Reference :

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

Advertisement