Skip to content

Commit

Permalink
Add CLI option to show version
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed Jul 24, 2017
1 parent 4a3db93 commit a5d7e58
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
Expand All @@ -18,16 +19,27 @@ const defaultPort = 6065
// verbose tracks whether the program is operating in verbose mode
var verbose bool

// This is set to the actual version by GoReleaser as it's run. Versions built
// from source will always show master.
var version = "master"

// ---

func main() {
var showVersion bool
var port int
var unix string
flag.IntVar(&port, "port", 0, "Port to listen on")
flag.StringVar(&unix, "unix", "", "Unix socket to listen on")
flag.BoolVar(&verbose, "verbose", false, "Enable verbose mode")
flag.BoolVar(&showVersion, "version", false, "Show version")
flag.Parse()

if showVersion || len(flag.Args()) == 1 && flag.Arg(0) == "version" {
fmt.Printf("%s\n", version)
return
}

if unix != "" && port != 0 {
flag.Usage()
log.Fatalf("Specify only one of -port or -unix")
Expand Down

0 comments on commit a5d7e58

Please sign in to comment.