diff --git a/Makefile b/Makefile index 83baeac..ed9e146 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ +VERSION=2.0 +LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION}" + test: go test ./... build: - go build . + go build ${LDFLAGS} diff --git a/main.go b/main.go index a0baa21..2d1e095 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,28 @@ package main import ( "mapserver/params" "mapserver/worldconfig" + "flag" "fmt" ) +var ( + Version string +) + func main() { p := params.Parse() + if p.Help { + flag.PrintDefaults() + return + } + + if p.Version { + fmt.Print("Mapserver version: ") + if Version == "" { + Version = "SNAPSHOT" + } + fmt.Println(Version) return } diff --git a/params/params.go b/params/params.go index 46221ee..a9210f4 100644 --- a/params/params.go +++ b/params/params.go @@ -8,6 +8,7 @@ type ParamsType struct { Worlddir string Port int Help bool + Version bool } func Parse() ParamsType { @@ -16,11 +17,8 @@ func Parse() ParamsType { flag.StringVar(&(params.Worlddir), "worlddir", "./", "world directory") flag.IntVar(&(params.Port), "port", 8080, "port to use") flag.BoolVar(&(params.Help), "help", false, "Show help") + flag.BoolVar(&(params.Version), "version", false, "Show version") flag.Parse() - if params.Help { - flag.PrintDefaults() - } - return params }