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
+29.2k Golang : missing Git command
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+16k Golang : How to reverse elements order in map ?
+35.3k Golang : Strip slashes from string example
+11.1k Golang : Simple image viewer with Go-GTK
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+33.8k Golang : convert(cast) bytes to string
+15.2k Golang : Save(pipe) HTTP response into a file
+17.9k Golang : Qt image viewer example
+14.6k Golang : How to get URL port?
+9.9k Golang : Turn string or text file into slice example
+22.5k Golang : Convert Unix timestamp to UTC timestamp