Skip to content

Commit

Permalink
feat: build commit support on version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Mar 28, 2021
1 parent b2d0ebb commit b21365e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%m:%S')
BUILD_VCS_REF ?= $(shell git rev-parse --short HEAD)

install:
@go version
Expand All @@ -16,8 +17,12 @@ test:
build:
@go version
@go build -v \
-ldflags "-s -w -X 'main.version=0.0.0' -X 'main.buildTime=$(BUILD_TIME)'" \
-ldflags "-s -w \
-X 'main.version=0.0.0' \
-X 'main.buildTime=$(BUILD_TIME)' \
-X 'main.buildCommit=$(BUILD_VCS_REF)'" \
-a -o bin/cline ./examples
@ls -ogh bin/cline
.PHONY: build

coverage:
Expand Down
1 change: 1 addition & 0 deletions app_printing.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (app *App) printVersion() error {
fmt.Printf("Version: %s\n", app.Version)
fmt.Printf("Go version: %s\n", runtime.Version())
fmt.Printf("Built: %s\n", app.BuildTime)
fmt.Printf("Commit: %s\n", app.BuildCommit)
fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
return nil
}
15 changes: 8 additions & 7 deletions cline.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ type CmdHandler func(*CmdContext) error

// App defines application settings
type App struct {
Name string
Summary string
Version string
BuildTime string
Flags []Flag
Commands []Cmd
Handler AppHandler
Name string
Summary string
Version string
BuildTime string
BuildCommit string
Flags []Flag
Commands []Cmd
Handler AppHandler
}

// AppContext defines an application context.
Expand Down
6 changes: 4 additions & 2 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
// App version and build time values passed at compile time
// See `Makefile` > build
var (
version string = "devel"
buildTime string
version string = "devel"
buildTime string
buildCommit string
)

func main() {
Expand All @@ -20,6 +21,7 @@ func main() {
app.Summary = "Run a program in a modified environment using .env files"
app.Version = version
app.BuildTime = buildTime
app.BuildCommit = buildCommit
app.Flags = []cli.Flag{
cli.FlagString{
Name: "file",
Expand Down

0 comments on commit b21365e

Please sign in to comment.