From 407bfbfb7ef95c971424440001e49ee06ec5b0f3 Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Tue, 26 Mar 2019 23:26:54 +0100 Subject: [PATCH] add version flag --- Makefile | 6 ++++++ config.go | 5 +++-- main.go | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..819159b --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +VERSION=`git describe --tags --dirty --always` + +LDFLAGS=-ldflags "-X main.version=${VERSION}" + +build: + go build ${LDFLAGS} ${OPTS} \ No newline at end of file diff --git a/config.go b/config.go index 5d0ade6..bf0a424 100644 --- a/config.go +++ b/config.go @@ -19,9 +19,10 @@ type config struct { Interface string `desc:"name of the wireguard interface to create and manage" default:"wgoverlay"` NoEtcHosts bool `id:"no-etc-hosts" desc:"disable writing of entries to /etc/hosts"` LogLevel string `id:"log-level" desc:"set the verbosity (debug/info/warn/error)" default:"warn"` + Version bool `desc:"display current version and exit"` - // for easier local testing - UseIPAsName bool `default:"false" opts:"hidden"` + // for easier local testing; will break etchosts entry + UseIPAsName bool `id:"ip-as-name" default:"false" opts:"hidden"` } func loadConfig() (*config, error) { diff --git a/main.go b/main.go index 318e009..303c095 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main // import "github.com/costela/wesher" import ( + "fmt" "os" "os/signal" "syscall" @@ -10,11 +11,17 @@ import ( "github.com/costela/wesher/etchosts" ) +var version = "dev" + func main() { config, err := loadConfig() if err != nil { logrus.Fatal(err) } + if config.Version { + fmt.Println(version) + os.Exit(0) + } logLevel, err := logrus.ParseLevel(config.LogLevel) if err != nil { logrus.Fatalf("could not parse loglevel: %s", err)