Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oya --version with build version #40

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}