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 :
Advertisement
Something interesting
Tutorials
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+16k Golang : Read large file with bufio.Scanner cause token too long error
+12k Golang : Convert a rune to unicode style string \u
+13.3k Golang : Date and Time formatting
+10.2k Golang : Check a web page existence with HEAD request example
+13.1k Golang : Convert(cast) uintptr to string example
+12.7k Golang : Add ASCII art to command line application launching process
+13.4k Golang : Verify token from Google Authenticator App
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+6.4k PHP : Proper way to get UTF-8 character or string length
+8.8k Golang : Accept any number of function arguments with three dots(...)