version info

This commit is contained in:
Thomas Rudin 2019-01-07 08:56:02 +01:00
parent 38787bcca2
commit d916f0e03c
3 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,9 @@
VERSION=2.0
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION}"
test:
go test ./...
build:
go build .
go build ${LDFLAGS}

16
main.go
View File

@ -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
}

View File

@ -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
}