Skip to content

Commit

Permalink
Embed version into CLI (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
edeNFed authored Oct 14, 2022
1 parent 26b2510 commit 289d4f6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ builds:
- windows
- darwin
dir: ./cli
ldflags:
- -X github.com/keyval-dev/odigos/cli/cmd.OdigosVersion={{ .Tag }}
- -X github.com/keyval-dev/odigos/cli/cmd.OdigosCommit={{ .ShortCommit }}
- -X github.com/keyval-dev/odigos/cli/cmd.OdigosDate={{ .Date }}
archives:
- replacements:
darwin: Darwin
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

const (
defaultNamespace = "odigos-system"
defaultVersion = "v0.1.3"
)

var (
Expand Down Expand Up @@ -262,6 +261,6 @@ func createKubeResourceWithLogging(ctx context.Context, msg string, client *kube
func init() {
rootCmd.AddCommand(installCmd)
installCmd.Flags().StringVarP(&namespaceFlag, "namespace", "n", defaultNamespace, "target namespace for Odigos installation")
installCmd.Flags().StringVar(&versionFlag, "version", defaultVersion, "target version for Odigos installation")
installCmd.Flags().StringVar(&versionFlag, "version", OdigosVersion, "target version for Odigos installation")
installCmd.Flags().BoolVar(&skipWait, "nowait", false, "Skip waiting for pods to be ready")
}
46 changes: 46 additions & 0 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
OdigosVersion string
OdigosCommit string
OdigosDate string
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("version.Info{Version:'%s', GitCommit:'%s', BuildDate:'%s'}\n", OdigosVersion, OdigosCommit, OdigosDate)
},
}

func init() {
rootCmd.AddCommand(versionCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

0 comments on commit 289d4f6

Please sign in to comment.