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
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+7.9k Javascript : Put image into Chrome browser's console
+12k Golang : Convert a rune to unicode style string \u
+7.5k Golang : Gorrila set route name and get the current route name
+19.9k Golang : Count JSON objects and convert to slice/array
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+6.5k Golang : Spell checking with ispell example
+14.8k Golang : Normalize unicode strings for comparison purpose
+9.2k Golang : How to control fmt or log print format?
+32.5k Golang : Copy directory - including sub-directories and files