Skip to content

Commit 5e19e2c

Browse files
committed
支持显示版本 --version
1 parent 16c9748 commit 5e19e2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

main.go

+11
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ import (
66
"net/http"
77
"os"
88
"path/filepath"
9+
"runtime/debug"
910
)
1011

1112
var dir string
1213
var port string
14+
var version bool
1315

1416
func init() {
1517
flag.StringVar(&port, "p", "8100", "port to serve on")
1618
flag.StringVar(&dir, "path", "./", "the directory of static file to host")
19+
flag.BoolVar(&version, "version", false, "print program version")
1720
flag.Parse()
21+
22+
if version {
23+
info, ok := debug.ReadBuildInfo()
24+
if ok {
25+
println(info.Main.Version, info.Main.Sum)
26+
}
27+
os.Exit(0)
28+
}
1829
if dir == "./" {
1930
dir, _ = os.Getwd()
2031
}

0 commit comments

Comments
 (0)