Add a -v flag to print version information

This commit is contained in:
Noah 2019-06-05 16:28:59 -07:00
parent 7376947e8a
commit e2cfb2d70c

View File

@ -27,6 +27,7 @@ var (
var ( var (
fDebug bool fDebug bool
fAddress string fAddress string
fVersion bool
) )
func init() { func init() {
@ -34,11 +35,17 @@ func init() {
flag.BoolVar(&fDebug, "d", false, "Debug mode (alias)") flag.BoolVar(&fDebug, "d", false, "Debug mode (alias)")
flag.StringVar(&fAddress, "address", ":8000", "Bind address") flag.StringVar(&fAddress, "address", ":8000", "Bind address")
flag.StringVar(&fAddress, "a", ":8000", "Bind address (alias)") flag.StringVar(&fAddress, "a", ":8000", "Bind address (alias)")
flag.BoolVar(&fVersion, "v", false, "Print version info and quit")
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
} }
func main() { func main() {
flag.Parse() flag.Parse()
if fVersion {
fmt.Printf("This is blog v%s build %s", Version, Build)
return
}
userRoot := flag.Arg(0) userRoot := flag.Arg(0)
if userRoot == "" { if userRoot == "" {
fmt.Printf("Need user root\n") fmt.Printf("Need user root\n")