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
+25.7k Golang : How to write CSV data to file
+10.6k Golang : Get local time and equivalent time in different time zone
+26.7k Golang : How to check if a connection to database is still alive ?
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+5.4k Golang : fmt.Println prints out empty data from struct
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+22.1k Golang : Join arrays or slices example
+5.9k Golang : Extract unicode string from another unicode string example
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+34k Golang : Proper way to set function argument default value
+8.8k Golang : Accept any number of function arguments with three dots(...)