| 
 | 1 | +package cmd  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"fmt"  | 
 | 5 | + | 
 | 6 | +	"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"  | 
 | 11 | + | 
 | 12 | +	"github.com/openmcp-project/bootstrapper/internal/version"  | 
 | 13 | +)  | 
 | 14 | + | 
 | 15 | +// versionCmd represents the version command  | 
 | 16 | +var versionCmd = &cobra.Command{  | 
 | 17 | +	Use:   "version",  | 
 | 18 | +	Short: "Print the version information",  | 
 | 19 | +	Long: `Print the version information of the openMCP bootstrapper CLI.  | 
 | 20 | +
  | 
 | 21 | +This command displays detailed version information including the build version,  | 
 | 22 | +Git commit, build date, Go version, and platform information.`,  | 
 | 23 | +	Run: func(cmd *cobra.Command, args []string) {  | 
 | 24 | +		ownVersion := version.GetVersion()  | 
 | 25 | + | 
 | 26 | +		if ownVersion == nil {  | 
 | 27 | +			fmt.Println("Version information not available")  | 
 | 28 | +			return  | 
 | 29 | +		}  | 
 | 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 | +}  | 
 | 49 | + | 
 | 50 | +func printVersion(v *apimachineryversion.Info, header string) {  | 
 | 51 | +	fmt.Printf("\n%s\n", header)  | 
 | 52 | +	fmt.Printf("========================\n")  | 
 | 53 | +	fmt.Printf("Version:      %s\n", v.GitVersion)  | 
 | 54 | +	if v.GitCommit != "" {  | 
 | 55 | +		fmt.Printf("Git Commit:   %s\n", v.GitCommit)  | 
 | 56 | +	}  | 
 | 57 | +	if v.GitTreeState != "" {  | 
 | 58 | +		fmt.Printf("Git State:    %s\n", v.GitTreeState)  | 
 | 59 | +	}  | 
 | 60 | +	if v.BuildDate != "" {  | 
 | 61 | +		fmt.Printf("Build Date:   %s\n", v.BuildDate)  | 
 | 62 | +	}  | 
 | 63 | +	fmt.Printf("Go Version:   %s\n", v.GoVersion)  | 
 | 64 | +	fmt.Printf("Compiler:     %s\n", v.Compiler)  | 
 | 65 | +	fmt.Printf("Platform:     %s\n", v.Platform)  | 
 | 66 | +	fmt.Printf("===================\n")  | 
 | 67 | +}  | 
 | 68 | + | 
 | 69 | +func init() {  | 
 | 70 | +	RootCmd.AddCommand(versionCmd)  | 
 | 71 | +}  | 
0 commit comments