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 endif
LUME_VERSION ?= $(shell git describe --tags --always) LUME_VERSION ?= $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := $(LDFLAGS) \ LDFLAGS := $(LDFLAGS) \
-X git.kill0.net/chill9/lume/cmd.Version=$(LUME_VERSION) \ -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 .PHONY: build
build: build:

View File

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

View File

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