Golang flag.PrintDefaults() function example
package flag
PrintDefaults prints to standard error the default values of all defined command-line flags.
Golang flag.PrintDefaults() function usage example
package main
import (
"flag"
"fmt"
"os"
)
var printHelp bool
var printVerbose string
func setFlags(printHelp *bool) {
flag.BoolVar(printHelp, "help", true, "Print this help message.")
flag.StringVar(&printVerbose, "verbose", "on | off", "Turn verbose mode on or off.")
}
func main() {
setFlags(&printHelp)
flag.Parse()
if printHelp {
fmt.Println("-----------------------------")
flag.PrintDefaults()
fmt.Println("-----------------------------")
os.Exit(0)
}
}
Output :
-----------------------------
-help=true: Print this help message.
-verbose="on | off": Turn verbose mode on or off.
-----------------------------
Reference :
Advertisement
Something interesting
Tutorials
+13.2k Golang : How to determine if a year is leap year?
+27.5k Golang : Connect to database (MySQL/MariaDB) server
+4.8k Golang : Pad file extension automagically
+5.6k Golang : Experimenting with the Rejang script
+6.3k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+13.2k Golang : Check if an integer is negative or positive
+7.4k Golang : What fmt.Println() can do and println() cannot do
+19.6k Golang : Count number of digits from given integer value
+10.1k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+10.7k CodeIgniter : How to check if a session exist in PHP?
+6.6k CloudFlare : Another way to get visitor's real IP address
+5k Gogland : Datasource explorer