Skip to content

Commit

Permalink
New version format
Browse files Browse the repository at this point in the history
  • Loading branch information
xitonix committed Dec 12, 2019
1 parent 0b1ec19 commit 953b1bb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ WINDOWS=./bin/windows_amd64
LINUX=./bin/linux_amd64
DARWIN=./bin/darwin_amd64
VERSION=$(shell git describe --tags --abbrev=0)
COMMIT=$(shell git rev-parse HEAD)
BUILT := $(shell date -u '+%a, %d %b %Y %H:%M:%S GMT')
RUNTIME=$(shell go version | cut -d' ' -f 3)

prepare:
@echo Cleaning the bin directory
@rm -rfv ./bin/*

windows:
@echo Building Windows amd64 binaries
@env GOOS=windows GOARCH=amd64 go build -i -v -o $(WINDOWS)/$(EXECUTABLE).exe -ldflags="-s -w -X main.version=$(VERSION)" *.go
@env GOOS=windows GOARCH=amd64 go build -i -v -o $(WINDOWS)/$(EXECUTABLE).exe -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go

linux:
@echo Building Linux amd64 binaries
@env GOOS=linux GOARCH=amd64 go build -i -v -o $(LINUX)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION)" *.go
@env GOOS=linux GOARCH=amd64 go build -i -v -o $(LINUX)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go

darwin:
@echo Building Mac amd64 binaries
@env GOOS=darwin GOARCH=amd64 go build -i -v -o $(DARWIN)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION)" *.go
@env GOOS=darwin GOARCH=amd64 go build -i -v -o $(DARWIN)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go

build: ## Builds the binaries.
build: windows linux darwin
Expand Down
2 changes: 1 addition & 1 deletion application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newApplication() error {
global := &commands.GlobalParameters{}
bindAppFlags(app, global)

commands.AddVersionCommand(app, version)
commands.AddVersionCommand(app, version, commit, built, runtimeVer)
commands.AddConsumeCommand(app, global)
commands.AddBrokerCommand(app, global)
commands.AddTopicCommand(app, global)
Expand Down
27 changes: 20 additions & 7 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,40 @@ package commands

import (
"fmt"
"strings"

"gopkg.in/alecthomas/kingpin.v2"
)

type version struct {
version string
app *kingpin.Application
version string
commit string
built string
runtimeVer string
app *kingpin.Application
}

func AddVersionCommand(app *kingpin.Application, appVersion string) {
func AddVersionCommand(app *kingpin.Application, appVersion, commit, built, runtimeVer string) {
cmd := &version{
version: appVersion,
app: app,
version: appVersion,
commit: commit,
built: built,
runtimeVer: runtimeVer,
app: app,
}
app.Command("version", "Prints the current version of Trubka.").Action(cmd.run)
}

func (c *version) run(ctx *kingpin.ParseContext) error {
func (c *version) run(*kingpin.ParseContext) error {
if c.version == "" {
c.version = "[built from source]"
}
fmt.Printf("%s %s\n", c.app.Name, c.version)
b := strings.Builder{}
b.WriteString("\nTrubka - A CLI Tool for Kafka\n\n")
b.WriteString(fmt.Sprintf(" Version: %s\n", c.version))
b.WriteString(fmt.Sprintf(" Runtime: %s\n", c.runtimeVer))
b.WriteString(fmt.Sprintf(" Built: %s\n", c.built))
b.WriteString(fmt.Sprintf(" Commit: %s\n", c.commit))
fmt.Println(b.String())
return nil
}
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import (
"github.com/xitonix/trubka/internal"
)

var version string
// Version build flags
var (
version string
commit string
runtimeVer string
built string
)

var enabledColor bool

func main() {
Expand Down

0 comments on commit 953b1bb

Please sign in to comment.