Skip to content

Instantly share code, notes, and snippets.

@physacco
Created March 10, 2013 05:04
Show Gist options
  • Save physacco/5127204 to your computer and use it in GitHub Desktop.
Save physacco/5127204 to your computer and use it in GitHub Desktop.
Test the usage of the flag package in go's stdlib.
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