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
+5.3k Python : Convert(cast) string to bytes example
+13.9k Golang : How to determine if a year is leap year?
+15.6k Golang : How to convert(cast) IP address to string?
+7.5k Golang : How to stop user from directly running an executable file?
+7.5k Golang : Gorrila set route name and get the current route name
+15.3k nginx: [emerg] unknown directive "ssl"
+12.3k Golang : Validate email address
+5.6k Swift : Get substring with rangeOfString() function example
+6k Javascript : Get operating system and browser information
+6.9k Golang : How to solve "too many .rsrc sections" error?
+16.4k Golang : How to implement two-factor authentication?
+12.7k Golang : Remove or trim extra comma from CSV