File tree Expand file tree Collapse file tree 7 files changed +58
-18
lines changed Expand file tree Collapse file tree 7 files changed +58
-18
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ func Run() {
6464
6565 c , err := cli .New (
6666 cli .WithCommandName ("kubebuilder" ),
67- cli .WithVersion (versionString ()),
67+ cli .WithVersion (versionMap ()),
6868 cli .WithCliVersion (getKubebuilderVersion ()),
6969 cli .WithPlugins (
7070 golangv4.Plugin {},
Original file line number Diff line number Diff line change @@ -59,17 +59,19 @@ type version struct {
5959}
6060
6161// versionString returns the Full CLI version
62- func versionString () string {
62+ func versionMap () map [ string ] string {
6363 kubeBuilderVersion = getKubebuilderVersion ()
64-
65- return fmt .Sprintf ("Version: %#v" , version {
66- kubeBuilderVersion ,
67- kubernetesVendorVersion ,
68- gitCommit ,
69- buildDate ,
70- goos ,
71- goarch ,
72- })
64+
65+ version := map [string ]string {
66+ "kubebuilder" : kubeBuilderVersion ,
67+ "kubernetes" : kubernetesVendorVersion ,
68+ "buildDate" : buildDate ,
69+ "gitCommit" : gitCommit ,
70+ "os" : goos ,
71+ "arch" : goarch ,
72+ }
73+
74+ return version
7375}
7476
7577// getKubebuilderVersion returns only the CLI version string
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ type CLI struct {
4949 // Root command name. It is injected downstream to provide correct help, usage, examples and errors.
5050 commandName string
5151 // Full CLI version string.
52- version string
52+ version map [ string ] string
5353 // CLI version string (just the CLI version number, no extra information).
5454 cliVersion string
5555 // CLI root's command description.
@@ -527,7 +527,7 @@ func (c *CLI) addSubcommands() {
527527
528528 // kubebuilder version
529529 // Only add version if a version string was provided
530- if c .version != "" {
530+ if c .version != nil {
531531 c .cmd .AddCommand (c .newVersionCmd ())
532532 }
533533}
Original file line number Diff line number Diff line change @@ -623,7 +623,14 @@ plugins:
623623
624624 When ("providing a version string" , func () {
625625 It ("should create a valid CLI" , func () {
626- const version = "version string"
626+ version := map [string ]string {
627+ "kubebuilder" : "123" ,
628+ "kubernetes" : "123" ,
629+ "buildDate" : "2025/12/3" ,
630+ "gitCommit" : "0123fasdf0123" ,
631+ "os" : "os123" ,
632+ "arch" : "arch123" ,
633+ }
627634 c , err = New (
628635 WithPlugins (& golangv4.Plugin {}),
629636 WithDefaultPlugins (projectVersion , & golangv4.Plugin {}),
@@ -648,7 +655,19 @@ plugins:
648655 Expect (err ).NotTo (HaveOccurred ())
649656 printed , _ := io .ReadAll (r )
650657 Expect (string (printed )).To (Equal (
651- fmt .Sprintf ("%s\n " , version )))
658+ fmt .Sprintf (`Kubebuilder: %v
659+ Kubernetes: %v
660+ Git Commit: %v
661+ Build date: %v
662+ OS/Arch: %v/%v
663+ ` ,
664+ version ["kubebuilder" ],
665+ version ["kubernetes" ],
666+ version ["gitCommit" ],
667+ version ["buildDate" ],
668+ version ["os" ],
669+ version ["arch" ],
670+ )))
652671 })
653672 })
654673
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ func WithCommandName(name string) Option {
5050}
5151
5252// WithVersion is an Option that defines the version string of the CLI.
53- func WithVersion (version string ) Option {
53+ func WithVersion (version map [ string ] string ) Option {
5454 return func (c * CLI ) error {
5555 c .version = version
5656 return nil
Original file line number Diff line number Diff line change @@ -540,7 +540,14 @@ var _ = Describe("CLI options", func() {
540540
541541 Context ("WithVersion" , func () {
542542 It ("should use the provided version string" , func () {
543- version := "Version: 0.0.0"
543+ version := map [string ]string {
544+ "kubebuilder" : "123" ,
545+ "kubernetes" : "123" ,
546+ "buildDate" : "2025/12/3" ,
547+ "gitCommit" : "0123fasdf0123" ,
548+ "os" : "os123" ,
549+ "arch" : "arch123" ,
550+ }
544551 c , err = newCLI (WithVersion (version ))
545552 Expect (err ).NotTo (HaveOccurred ())
546553 Expect (c ).NotTo (BeNil ())
Original file line number Diff line number Diff line change @@ -29,7 +29,19 @@ func (c CLI) newVersionCmd() *cobra.Command {
2929 Long : fmt .Sprintf ("Print the %s version" , c .commandName ),
3030 Example : fmt .Sprintf ("%s version" , c .commandName ),
3131 RunE : func (_ * cobra.Command , _ []string ) error {
32- fmt .Println (c .version )
32+ fmt .Printf (`Kubebuilder: %v
33+ Kubernetes: %v
34+ Git Commit: %v
35+ Build date: %v
36+ OS/Arch: %v/%v
37+ ` ,
38+ c .version ["kubebuilder" ],
39+ c .version ["kubernetes" ],
40+ c .version ["gitCommit" ],
41+ c .version ["buildDate" ],
42+ c .version ["os" ],
43+ c .version ["arch" ],
44+ )
3345 return nil
3446 },
3547 }
You can’t perform that action at this time.
0 commit comments