Add git commit to version output

This commit is contained in:
Ryan Cavicchioni 2021-03-10 21:39:47 -06:00
parent 1a7b665376
commit 94cc596afa
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
3 changed files with 18 additions and 8 deletions

View File

@ -12,9 +12,11 @@ else
endif
LUME_VERSION ?= $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := $(LDFLAGS) \
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \
-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE)
-X git.kill0.net/chill9/lume/cmd.BuildDate=$(BUILD_DATE) \
-X git.kill0.net/chill9/lume/cmd.GitCommit=$(GIT_COMMIT)
.PHONY: build
build:

View File

@ -29,8 +29,9 @@ func init() {
RegisterCommand(NewCmdVersion())
}
var Version string = "0.1.0-pre"
var Version string
var BuildDate string
var GitCommit string
const lumercFile string = ".lumerc"

View File

@ -2,7 +2,7 @@ package lumecmd
import (
"fmt"
"runtime"
"strings"
)
func NewCmdVersion() Command {
@ -16,11 +16,18 @@ func NewCmdVersion() Command {
}
func VersionCmd(args CmdArgs) (int, error) {
fmt.Printf("lume %s\n", Version)
fmt.Printf(" os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf(" go version: %s\n", runtime.Version())
if BuildDate != "" {
fmt.Printf(" build date: %s\n", BuildDate)
var b strings.Builder
fmt.Fprintf(&b, "lume %s", Version)
b.WriteString(" ")
if GitCommit != "" {
fmt.Fprintf(&b, "(git: %s)", GitCommit)
b.WriteString(" ")
}
if BuildDate != "" {
fmt.Fprintf(&b, "build_date: %s", BuildDate)
}
fmt.Println(b.String())
return ExitSuccess, nil
}