Skip to content

Commit

Permalink
root: added --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Jan 8, 2021
1 parent 03d1b9a commit b23049e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ builds:
- linux
- windows
- darwin
ldflags: -s -w -X github.com/craftamap/bb/cmd.Version={{ .Version }} -X github.com/craftamap/bb/cmd.CommitSHA={{ .Commit }}

archives:
- replacements:
darwin: Darwin
Expand Down
14 changes: 14 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
)

var (
Version = ""
CommitSHA = ""

rootCmd = &cobra.Command{
Use: "bb",
Short: "Bitbucket.org CLI",
Expand Down Expand Up @@ -99,6 +102,17 @@ func init() {
auth.Add(rootCmd, &globalOpts)
repo.Add(rootCmd, &globalOpts)
pipelines.Add(rootCmd, &globalOpts)


if CommitSHA != "" {
vt := rootCmd.VersionTemplate()
rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA + ")\n")
}
if Version == "" {
Version = "unknown (built from source)"
}

rootCmd.Version = Version
}

func initConfig() {
Expand Down

0 comments on commit b23049e

Please # to comment.