Skip to content

Commit

Permalink
get version from ldflags (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrancej authored Aug 18, 2020
1 parent 34e0cdd commit 564d066
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 6 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
"github.com/spf13/viper"
)

var cfgFile string

const version = "v0.1.13"
var (
meroxaVersion string
cfgFile string
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand All @@ -44,7 +45,8 @@ meroxa list resource-types`,

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(version string) {
meroxaVersion = version
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "display the version of the Meroxa CLI",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Meroxa CLI version %s\n", version)
fmt.Printf("Meroxa CLI version %s\n", meroxaVersion)
},
}

Expand All @@ -35,5 +35,5 @@ func init() {
}

func versionString() string {
return fmt.Sprintf("meroxa cli %s", version)
return fmt.Sprintf("meroxa cli %s", meroxaVersion)
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package main

import "github.com/meroxa/cli/cmd"

var version = "dev"

func main() {
cmd.Execute()
cmd.Execute(version)
}

0 comments on commit 564d066

Please sign in to comment.