Skip to content

Commit 603c828

Browse files
authored
Merge pull request #24 from feloy/version
Add --version option
2 parents 3fbc615 + 30753f9 commit 603c828

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cmd/kubectl-tree/rootcmd.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,29 @@ import (
3232

3333
var cf *genericclioptions.ConfigFlags
3434

35+
// This variable is populated by goreleaser
36+
var version string
37+
3538
// rootCmd represents the base command when called without any subcommands
3639
var rootCmd = &cobra.Command{
3740
Use: "kubectl tree KIND NAME",
3841
SilenceUsage: true, // for when RunE returns an error
3942
Short: "Show sub-resources of the Kubernetes object",
4043
Example: " kubectl tree deployment my-app\n" +
4144
" kubectl tree kservice.v1.serving.knative.dev my-app", // TODO add more examples about disambiguation etc
42-
Args: cobra.MinimumNArgs(2),
43-
RunE: run,
45+
Args: cobra.MinimumNArgs(2),
46+
RunE: run,
47+
Version: versionString(),
48+
}
49+
50+
// versionString returns the version prefixed by 'v'
51+
// or an empty string if no version has been populated by goreleaser.
52+
// In this case, the --version flag will not be added by cobra.
53+
func versionString() string {
54+
if len(version) == 0 {
55+
return ""
56+
}
57+
return "v" + version
4458
}
4559

4660
func run(_ *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)