Skip to content

Commit ff79978

Browse files
committed
add version command
1 parent 57f101a commit ff79978

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

cmd/version.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7+
apimachineryversion "k8s.io/apimachinery/pkg/version"
8+
"sigs.k8s.io/yaml"
9+
10+
ocmcli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
711

812
"github.com/openmcp-project/bootstrapper/internal/version"
913
)
@@ -17,18 +21,35 @@ var versionCmd = &cobra.Command{
1721
This command displays detailed version information including the build version,
1822
Git commit, build date, Go version, and platform information.`,
1923
Run: func(cmd *cobra.Command, args []string) {
20-
printVersion()
21-
},
22-
}
24+
ownVersion := version.GetVersion()
2325

24-
func printVersion() {
25-
v := version.GetVersion()
26+
if ownVersion == nil {
27+
fmt.Println("Version information not available")
28+
return
29+
}
2630

27-
if v == nil {
28-
fmt.Println("Version information not available")
29-
return
30-
}
31+
printVersion(ownVersion, "openMCP Bootstrapper CLI")
32+
33+
var ocmVersion apimachineryversion.Info
34+
out, err := ocmcli.ExecuteOutput(cmd.Context(), []string{"version"}, nil, ocmcli.NoOcmConfig)
35+
if err != nil {
36+
fmt.Printf("Error retrieving ocm-cli version: %ownVersion\n", err)
37+
return
38+
}
39+
40+
err = yaml.Unmarshal(out, &ocmVersion)
41+
if err != nil {
42+
fmt.Printf("Error parsing ocm-cli version output: %ownVersion\n", err)
43+
return
44+
}
45+
46+
printVersion(&ocmVersion, "OCM CLI")
47+
},
48+
}
3149

50+
func printVersion(v *apimachineryversion.Info, header string) {
51+
fmt.Printf("\n%s\n", header)
52+
fmt.Printf("========================\n")
3253
fmt.Printf("Version: %s\n", v.GitVersion)
3354
if v.GitCommit != "" {
3455
fmt.Printf("Git Commit: %s\n", v.GitCommit)
@@ -42,6 +63,7 @@ func printVersion() {
4263
fmt.Printf("Go Version: %s\n", v.GoVersion)
4364
fmt.Printf("Compiler: %s\n", v.Compiler)
4465
fmt.Printf("Platform: %s\n", v.Platform)
66+
fmt.Printf("===================\n")
4567
}
4668

4769
func init() {

0 commit comments

Comments
 (0)