add version flag
This commit is contained in:
parent
e89a7141e5
commit
407bfbfb7e
|
@ -0,0 +1,6 @@
|
|||
VERSION=`git describe --tags --dirty --always`
|
||||
|
||||
LDFLAGS=-ldflags "-X main.version=${VERSION}"
|
||||
|
||||
build:
|
||||
go build ${LDFLAGS} ${OPTS}
|
|
@ -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) {
|
||||
|
|
7
main.go
7
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)
|
||||
|
|
Loading…
Reference in New Issue