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
+9k Golang : Capture text return from exec function example
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+15.6k Golang : Force download file example
+9k Golang : automatically figure out array length(size) with three dots
+30.6k Golang : Remove characters from string example
+16.8k Golang : read gzipped http response
+8.8k Golang : Take screen shot of browser with JQuery example
+7.8k Golang : Scan files for certain pattern and rename part of the files
+14.4k Golang : On enumeration
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+12.6k Golang : Transform comma separated string to slice example