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
+51.9k Golang : How to get time in milliseconds?
+41k Golang : How to check if a string contains another sub-string?
+5.9k Golang : Extract unicode string from another unicode string example
+9.2k Golang : Generate Codabar
+14.5k How to automatically restart your crashed Golang server
+36.5k Golang : Validate IP address
+6.6k Golang : Warp text string by number of characters or runes example
+26.3k Golang : Calculate future date with time.Add() function
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+8.1k Golang : HTTP Server Example
+19.6k Golang : Get current URL example
+10.2k Golang : Random Rune generator