Skip to content

Commit

Permalink
support for the -v / --version cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
ARolek committed Jun 22, 2017
1 parent 5796068 commit d476496
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions cmd/tegola/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import (
)

var (
configFile = *flag.String("config", "config.toml", "")
logFile = *flag.String("log-file", "", "")
logFormat = *flag.String("log-format", server.DefaultLogFormat, "")
port = *flag.String("port", defaultHTTPPort, "")
configFile = flag.String("config", "config.toml", "")
logFile = flag.String("log-file", "", "")
logFormat = flag.String("log-format", server.DefaultLogFormat, "")
port = flag.String("port", defaultHTTPPort, "")
version = flag.Bool("version", false, "")
)

const defaultHTTPPort = ":8080"

func init() {
// short forms
flag.StringVar(configFile, "c", "config", "")
flag.BoolVar(version, "v", false, "")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, `tegola %v <http://tegola.io>
MVT tile server with support for PostGIS
Expand All @@ -27,7 +32,7 @@ USAGE: tegola [OPTIONS]
OPTIONS:
-h, --help Print usage
-v, --version Print version and quit
--config string Location of config file in TOML format. Can be local or remote over http(s) (default config.toml)
-c, --config string Location of config file in TOML format. Can be local or remote over http(s) (default config.toml)
--port string Port to bind HTTP server to (example :8080)
--log-file string The file to write request logs to (default disabled)
--log-format string The format the logger will log with. Available fields:
Expand Down
16 changes: 11 additions & 5 deletions cmd/tegola/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ func main() {
// parse our command line flags
flag.Parse()

// if the user looking for tegola version info, print it and exit
if *version {
fmt.Println(Version)
os.Exit(0)
}

defer setupProfiler().Stop()

conf, err := config.Load(configFile)
conf, err := config.Load(*configFile)
if err != nil {
log.Fatal(err)
}
Expand All @@ -51,19 +57,19 @@ func main() {
log.Fatal(err)
}

initLogger(logFile, logFormat, conf.Webserver.LogFile, conf.Webserver.LogFormat)
initLogger(*logFile, *logFormat, conf.Webserver.LogFile, conf.Webserver.LogFormat)

// check config for port setting
if port == defaultHTTPPort && conf.Webserver.Port != "" {
port = conf.Webserver.Port
if *port == defaultHTTPPort && conf.Webserver.Port != "" {
port = &conf.Webserver.Port
}

// set our server version
server.Version = Version
server.HostName = conf.Webserver.HostName

// start our webserver
server.Start(port)
server.Start(*port)
}

// initMaps registers maps with our server
Expand Down

0 comments on commit d476496

Please sign in to comment.