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
+13.4k Golang : Increment string example
+7.3k Golang : File system scanning
+7.1k Restart Apache or Nginx web server without password prompt
+5.7k Golang : Struct field tags and what is their purpose?
+7.4k Golang : Scanf function weird error in Windows
+7.1k Nginx : How to block user agent ?
+5.8k Linux : Disable and enable IPv4 forwarding
+16.9k Golang : Read integer from file into array
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+6.3k Golang : Test input string for unicode example
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+12.4k Golang : Search and extract certain XML data example