From db447eaa2e74307bb3794a682f54674d4cdb297c Mon Sep 17 00:00:00 2001 From: Eden Federman Date: Fri, 14 Oct 2022 10:31:41 +0300 Subject: [PATCH] Embed version into CLI --- .goreleaser.yaml | 4 ++++ cli/cmd/install.go | 3 +-- cli/cmd/version.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 cli/cmd/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 573be61f9..edbb06b37 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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 diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 27762b130..1a75dcfda 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -16,7 +16,6 @@ import ( const ( defaultNamespace = "odigos-system" - defaultVersion = "v0.1.3" ) var ( @@ -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") } diff --git a/cli/cmd/version.go b/cli/cmd/version.go new file mode 100644 index 000000000..d25ccbdff --- /dev/null +++ b/cli/cmd/version.go @@ -0,0 +1,46 @@ +/* +Copyright © 2022 NAME HERE + +*/ +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") +}