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"`
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) {

View File

@ -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)