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

Embed version into CLI #28

Merged
merged 1 commit into from
Oct 14, 2022
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
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")
}