Golang flag.FlagSet.PrintDefaults() function example
package flag
PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set.
Golang flag.FlagSet.PrintDefaults() function usage example
package main
import (
"flag"
"fmt"
)
var flagSet *flag.FlagSet
func main() {
flagSet = flag.NewFlagSet("example", flag.ContinueOnError)
flagSet.String("file", "", "filename to view")
flagSet.Int("timeout", 5000, "specify the time in milliseconds to wait for a response")
err := flagSet.Parse([]string{"file", "timeout"})
if err != nil {
fmt.Println(err)
}
flagSet.PrintDefaults()
}
Output :
-file="": filename to view
-timeout=5000: specify the time in milliseconds to wait for a response
Reference :
Advertisement
Something interesting
Tutorials
+22.9k Golang : Test file read write permission example
+31.1k Golang : Calculate percentage change of two values
+19.2k Golang : Delete item from slice based on index/key position
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+4.9k Python : Find out the variable type and determine the type with simple test
+8.1k Golang : Multiplexer with net/http and map
+13.5k Facebook PHP getUser() returns 0
+6k Golang : How to verify input is rune?
+16.7k Golang : Gzip file example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example