version flag
This commit is contained in:
parent
c2a17cceec
commit
2bb892175a
3
build.sh
Executable file
3
build.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
CGO_ENABLED=1 go build -ldflags "-X main.Version=1.2.3 -X main.GitHash=`git rev-parse HEAD` -X main.BuildTime=`date -u '+%Y-%m-%d_%I:%M:%S%p'`"
|
22
main.go
22
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
@ -19,6 +20,15 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is the app's version string
|
||||
Version = "UNKNOWN"
|
||||
// GitHash is the current git hash for this version
|
||||
GitHash = "UNKNOWN"
|
||||
// BuildTime is the time of build of this app
|
||||
BuildTime = "UNKNOWN"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("myLogger")
|
||||
|
||||
var inDir *string
|
||||
@ -537,8 +547,16 @@ func main() {
|
||||
createOutDir := flag.Bool("create", false, "create output directory if not existing")
|
||||
//clearOutDir := flag.Bool("clear", false, "clear output directory before generating website")
|
||||
logLevel := flag.String("logLevel", "info", "log level: debug, info, warning, error")
|
||||
version := flag.Bool("version", false, "print version of this executable")
|
||||
|
||||
flag.Parse()
|
||||
if version != nil && *version {
|
||||
fmt.Printf(`%11s: %s
|
||||
%11s: %s
|
||||
%11s: %s
|
||||
`, "version", Version, "git hash", GitHash, "build time", BuildTime)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.MustStringFormatter(
|
||||
@ -556,6 +574,10 @@ func main() {
|
||||
logBackendLevel = logging.INFO
|
||||
break
|
||||
|
||||
case "notice":
|
||||
logBackendLevel = logging.NOTICE
|
||||
break
|
||||
|
||||
case "warning":
|
||||
logBackendLevel = logging.WARNING
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user