Skip to content

Commit

Permalink
Use cobra's version command instead of our own
Browse files Browse the repository at this point in the history
It's funny what you learn when you actually read the docs. I just
learned that cobra has code to add a version flag so we don't have to.

Signed-off-by: Toby Cabot <[email protected]>
  • Loading branch information
caboteria committed Jul 18, 2023
1 parent 37a34d5 commit 015facb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 37 deletions.
13 changes: 9 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ import (

var (
scheme = runtime.NewScheme()

// version is set by the build process.
version string = "development"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "epicctl",
Short: "epicctl controls EPIC clusters",
Long: `epicctl controls EPIC clusters.`,
Use: "epicctl",
Short: "epicctl controls EPIC",
Long: `epicctl controls EPIC.`,
Version: version,
}

// Execute is called by main.main(). It only needs to happen once to the rootCmd.
Expand All @@ -46,9 +50,10 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(epicv1.AddToScheme(scheme))

cobra.OnInitialize(debugVersion)
cobra.OnInitialize(readConfigFile)

rootCmd.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "version: %s" .Version}}
`)
rootCmd.PersistentFlags().Bool("debug", false, "enable debug output")
rootCmd.PersistentFlags().String("config", path.Join(homedir.HomeDir(), ".epicctl.yaml"), "epicctl config file")
rootCmd.PersistentFlags().String(clientcmd.RecommendedConfigPathFlag, clientcmd.RecommendedHomeFile, "k8s config file")
Expand Down
33 changes: 0 additions & 33 deletions cmd/version.go

This file was deleted.

0 comments on commit 015facb

Please sign in to comment.