Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie committed Feb 14, 2018
1 parent 7dd48b4 commit 5f94044
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
@@ -1,12 +1,19 @@
OUTPUT ?= astro

GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT=$(shell git rev-parse --short HEAD)
VERSION ?= SNAPSHOT-${GIT_COMMIT_SHORT}

LDFLAGS_VERSION=-X github.com/astronomerio/astro-cli/cmd.version=${VERSION}
LDFLAGS_GIT_COMMIT=-X github.com/astronomerio/astro-cli/cmd.gitcommit=${GIT_COMMIT}

.DEFAULT_GOAL := build

dep:
dep ensure

build:
go build -o ${OUTPUT} main.go
go build -o ${OUTPUT} -ldflags "${LDFLAGS_VERSION} ${LDFLAGS_GIT_COMMIT}" main.go

install: build
$(eval DESTDIR ?= $(GOBIN))
Expand Down
28 changes: 28 additions & 0 deletions cmd/version.go
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
version = ""
gitcommit = ""
versionCmd = &cobra.Command{
Use: "version",
Short: "Astronomer CLI version",
Long: "Astronomer CLI version",
RunE: printVersion,
}
)

func init() {
RootCmd.AddCommand(versionCmd)
}

func printVersion(cmd *cobra.Command, args []string) error {
fmt.Printf("Astro CLI Version: %s\n", version)
fmt.Printf("Git Commit: %s\n", gitcommit)
return nil
}

0 comments on commit 5f94044

Please sign in to comment.