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
+36.3k Golang : How to split or chunking a file to smaller pieces?
+3.4k Golang : Fix go-cron set time not working issue
+6.1k PageSpeed : Clear or flush cache on web server
+11.2k Google Maps URL parameters configuration
+7.1k Nginx : How to block user agent ?
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+8.9k Golang : GMail API create and send draft with simple upload attachment example
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+30.8k Golang : Download file example
+5.2k Golang : The Tao of importing package
+17.9k Golang : Login and logout a user after password verification and redirect example
+12.4k Elastic Search : Return all records (higher than default 10)