Skip to content

Commit

Permalink
Merge pull request #40 from tooploox/bdymowski/oya-version
Browse files Browse the repository at this point in the history
Add oya --version with build version
  • Loading branch information
bart84ek committed Apr 25, 2019
2 parents 72df1bd + c41c7c2 commit d1779e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Oyafile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ lintFix: |
release: |
go get -u github.com/mitchellh/gox
go get -u github.com/tcnksm/ghr
gox -os="linux darwin" -arch="amd64 386" -output="dist/oya_${CIRCLE_TAG}_{{.OS}}_{{.Arch}}"
gox -os="linux darwin" -arch="amd64 386" -output="dist/oya_${CIRCLE_TAG}_{{.OS}}_{{.Arch}}" -ldflags="-X main.buildVersion=${CIRCLE_TAG}"
gzip dist/*
sha256sum dist/oya_${CIRCLE_TAG}_{darwin,linux}_* | tee dist/oya_${CIRCLE_TAG}_SHA256SUMS
if [ "$CIRCLE_TAG" ]; then
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func Execute() {
}
}

func SetOyaVersion(ver string) {
rootCmd.Version = ver
}

// ExecuteE executes a command same as Execute but returns error.
func ExecuteE() error {
_, err := rootCmd.ExecuteC()
Expand Down
13 changes: 12 additions & 1 deletion oya.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@

package main

import "github.com/tooploox/oya/cmd"
import (
"fmt"
"time"

"github.com/tooploox/oya/cmd"
)

var buildVersion string

func main() {
if buildVersion == "" {
buildVersion = fmt.Sprintf("build-%s", time.Now().Format("20060102.150405"))
}
cmd.SetOyaVersion(buildVersion)
cmd.Execute()
}

0 comments on commit d1779e9

Please sign in to comment.