diff --git a/Makefile b/Makefile index 5330a75e4..4826a56a6 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +VERSION = 0.0.1 +BUILD ?=$(shell git rev-parse --short HEAD) +PKG ?=github.com/commitdev/commit0 +BUILD_ARGS=-v -ldflags=all="-X ${PKG}/cmd.appVersion=${VERSION} -X ${PKG}/cmd.appBuild=${BUILD}" + check: go test ./... @@ -13,7 +18,7 @@ build-example-docker: clean-example docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) commit0:v0 generate -l go build: - go build -o commit0 + go build ${BUILD_ARGS} # Installs the CLI int your GOPATH install-go: diff --git a/cmd/version.go b/cmd/version.go index def3b099c..8423b7d06 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,6 +6,11 @@ import ( "github.com/spf13/cobra" ) +var ( + appVersion = "SNAPSHOT" + appBuild = "SNAPSHOT" +) + func init() { rootCmd.AddCommand(versionCmd) } @@ -14,6 +19,7 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of commit0", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("v0.0.0") // Updated via updateVersion.sh + fmt.Printf("version: %v\n", appVersion) + fmt.Printf("build: %v\n", appBuild) }, } diff --git a/updateVersion.sh b/updateVersion.sh deleted file mode 100755 index f847fecc2..000000000 --- a/updateVersion.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -VERSION=$1 - -if [ -z "$VERSION" ]; then - echo "Usage: ./updateVersion.sh " - exit 1 -fi - -sed "s/\t\tfmt.Println(\"v0.0.0\")/\t\tfmt.Println(\"${VERSION}\")/g" cmd/version.go > cmd/version.go.update - -mv cmd/version.go.update cmd/version.go \ No newline at end of file