Skip to content

Commit

Permalink
show commit and date in version command
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaysomani07 committed Feb 23, 2023
1 parent 77a91a5 commit 84a69ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Makefile
Expand Up @@ -3,6 +3,13 @@ NAME := cloudlens
OUTPUT_BIN ?= execs/${NAME}
PACKAGE := github.com/one2nc/$(NAME)
VERSION = v0.1.0
GIT_REV ?= $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
ifeq ($(shell uname), Darwin)
DATE ?= $(shell TZ=UTC date -j -f "%s" ${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
else
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
endif

setup:
docker-compose up -d
Expand All @@ -12,7 +19,7 @@ setup-down:

build:
go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/cmd.version=${VERSION}" \
-ldflags "-w -s -X ${PACKAGE}/cmd.version=${VERSION} -X ${PACKAGE}/cmd.commit=${GIT_REV} -X ${PACKAGE}/cmd.date=${DATE}" \
-a -tags netgo -o ${OUTPUT_BIN} main.go

run: build
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Expand Up @@ -19,7 +19,9 @@ import (

var (
profile, region string
version = ""
version = "dev"
commit = "dev"
date = "today"
rootCmd = &cobra.Command{
Use: `cloudlens`,
Short: `cli for aws services`,
Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Expand Up @@ -32,8 +32,8 @@ func printVersion(short bool) {
outputColor = -1
}
printTuple(fmat, "Version", version, outputColor)
// printTuple(fmat, "Commit", commit, outputColor)
// printTuple(fmat, "Date", date, outputColor)
printTuple(fmat, "Commit", commit, outputColor)
printTuple(fmat, "Date", date, outputColor)
}

func printTuple(fmat, section, value string, outputColor color.Paint) {
Expand Down

0 comments on commit 84a69ef

Please sign in to comment.