Skip to content

Commit

Permalink
feat: add -version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jun 19, 2019
1 parent ebb5a36 commit 4b2481e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions prometheus_nats_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/nats-io/prometheus-nats-exporter/exporter"
)

var version = "dev"

// parseServerIDAndURL parses the url argument the optional id for the server ID.
func parseServerIDAndURL(urlArg string) (string, string, error) {
var id string
Expand Down Expand Up @@ -83,10 +85,12 @@ func main() {
var useSysLog bool
var debugAndTrace bool
var retryInterval int
var printVersion bool

opts := exporter.GetDefaultExporterOptions()

// Parse flags
flag.BoolVar(&printVersion, "version", false, "Show exporter version and exit.")
flag.IntVar(&opts.ListenPort, "port", exporter.DefaultListenPort, "Port to listen on.")
flag.IntVar(&opts.ListenPort, "p", exporter.DefaultListenPort, "Port to listen on.")
flag.StringVar(&opts.ListenAddress, "addr", exporter.DefaultListenAddress, "Network host to listen on.")
Expand Down Expand Up @@ -117,6 +121,11 @@ func main() {

opts.RetryInterval = time.Duration(retryInterval) * time.Second

if printVersion {
fmt.Println("prometheus-nats-exporter version", version)
os.Exit(0)
}

args := flag.Args()
if len(args) < 1 {
fmt.Printf("Usage: %s <flags> url\n\n", os.Args[0])
Expand Down

0 comments on commit 4b2481e

Please sign in to comment.