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
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+13.9k Golang : How to check if a file is hidden?
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+14.4k Android Studio : Use image as AlertDialog title with custom layout example
+6.3k Javascript : Generate random key with specific length
+6.9k Nginx : Password protect a directory/folder
+12.2k Golang : Split strings into command line arguments
+9.2k Golang : Write multiple lines or divide string into multiple lines
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+5.9k AWS S3 : Prevent Hotlinking policy