add version flag

This commit is contained in:
Leo Antunes 2019-03-26 23:26:54 +01:00
parent e89a7141e5
commit 407bfbfb7e
3 changed files with 16 additions and 2 deletions

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
VERSION=`git describe --tags --dirty --always`
LDFLAGS=-ldflags "-X main.version=${VERSION}"
build:
go build ${LDFLAGS} ${OPTS}

View File

@ -19,9 +19,10 @@ type config struct {
Interface string `desc:"name of the wireguard interface to create and manage" default:"wgoverlay"` 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"` 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"` 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 // for easier local testing; will break etchosts entry
UseIPAsName bool `default:"false" opts:"hidden"` UseIPAsName bool `id:"ip-as-name" default:"false" opts:"hidden"`
} }
func loadConfig() (*config, error) { func loadConfig() (*config, error) {

View File

@ -1,6 +1,7 @@
package main // import "github.com/costela/wesher" package main // import "github.com/costela/wesher"
import ( import (
"fmt"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
@ -10,11 +11,17 @@ import (
"github.com/costela/wesher/etchosts" "github.com/costela/wesher/etchosts"
) )
var version = "dev"
func main() { func main() {
config, err := loadConfig() config, err := loadConfig()
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
if config.Version {
fmt.Println(version)
os.Exit(0)
}
logLevel, err := logrus.ParseLevel(config.LogLevel) logLevel, err := logrus.ParseLevel(config.LogLevel)
if err != nil { if err != nil {
logrus.Fatalf("could not parse loglevel: %s", err) logrus.Fatalf("could not parse loglevel: %s", err)