Skip to content

Commit

Permalink
Replace embedding version info with buildinfo (wtfutil#1328)
Browse files Browse the repository at this point in the history
* Replace embedding version info with buildinfo

* Less verbosity
  • Loading branch information
Seanstoppable authored Oct 5, 2022
1 parent 5424506 commit 67c8ecc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ install:
@echo "$$HEADER"
@echo "Installing ${APP} with ${GOVERS}..."
@go clean
@go install -ldflags="-s -w -X main.version=$(shell git describe --always --abbrev=6) -X main.date=$(shell date +%FT%T%z)"
@go install -ldflags="-s -w"
@mv $(GOBIN)/wtf $(GOBIN)/${APP}
$(eval INSTALLPATH = $(shell which ${APP}))
@echo "${APP} installed into ${INSTALLPATH}"
Expand Down
13 changes: 12 additions & 1 deletion flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"

"github.com/chzyer/readline"
Expand Down Expand Up @@ -54,13 +55,23 @@ func (flags *Flags) ConfigFilePath() string {

// RenderIf displays special-case information based on the flags passed
// in, if any flags were passed in
func (flags *Flags) RenderIf(version, date string, config *config.Config) {
func (flags *Flags) RenderIf(config *config.Config) {
if flags.HasModule() {
help.Display(flags.Module, config)
os.Exit(0)
}

if flags.HasVersion() {
info, _ := debug.ReadBuildInfo()
version := "dev"
date := "now"
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
version = setting.Value
} else if setting.Key == "vcs.time" {
date = setting.Value
}
}
fmt.Printf("%s (%s)\n", version, date)
os.Exit(0)
}
Expand Down
7 changes: 1 addition & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import (
"github.com/wtfutil/wtf/wtf"
)

var (
date = "dev"
version = "dev"
)

/* -------------------- Main -------------------- */

func main() {
Expand All @@ -41,7 +36,7 @@ func main() {

wtf.SetTerminal(config)

flags.RenderIf(version, date, config)
flags.RenderIf(config)

if flags.Profile {
defer profile.Start(profile.MemProfile).Stop()
Expand Down

0 comments on commit 67c8ecc

Please sign in to comment.