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
+15.2k Golang : Save(pipe) HTTP response into a file
+13.6k Android Studio : Password input and reveal password example
+19.4k Golang : How to count the number of repeated characters in a string?
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+22.2k Golang : Convert seconds to minutes and remainder seconds
+18.6k Golang : Generate thumbnails from images
+18.7k Golang : convert int to string
+8.1k Golang : HTTP Server Example
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+9.6k Golang : Validate IPv6 example
+14.1k Golang : Check if a file exist or not
+11.1k Golang : How to determine a prime number?