Created
March 10, 2013 05:04
-
-
Save physacco/5127204 to your computer and use it in GitHub Desktop.
Test the usage of the flag package in go's stdlib.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"fmt" | |
"flag" | |
) | |
func main() { | |
help := flag.Bool("help", false, "Print help message") | |
vsn := flag.Bool("version", false, "Print version info") | |
host := flag.String("host", "localhost", "Specify listening host") | |
port := flag.Int("port", 8000, "Specify listening port") | |
fmt.Println("flag.PrintDefaults: ") | |
flag.PrintDefaults() | |
fmt.Println() | |
fmt.Println("os.Args: ", os.Args) | |
fmt.Println() | |
flag.Parse() | |
fmt.Println("flag.Parse results: ") | |
fmt.Println(" help: ", *help) | |
fmt.Println(" vsn: ", *vsn) | |
fmt.Println(" host: ", *host) | |
fmt.Println(" port: ", *port) | |
fmt.Println(" Args: ", flag.Args()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment