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
+10.1k Golang : How to tokenize source code with text/scanner package?
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+6.7k Golang : Humanize and Titleize functions
+12.4k Golang : Search and extract certain XML data example
+16k Golang : Read large file with bufio.Scanner cause token too long error
+17.2k Golang : When to use init() function?
+8.2k Golang : Find relative luminance or color brightness
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+25.7k Golang : How to write CSV data to file
+6.3k Golang : Extract sub-strings
+4.1k Javascript : Empty an array example