mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 14:26:23 -04:00
Feat/more version info (#224)
This commit is contained in:
parent
3b92b52611
commit
0c9ca50be8
3 changed files with 96 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/edgelesssys/constellation/internal/constants"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -12,9 +14,56 @@ func NewVersionCmd() *cobra.Command {
|
|||
Short: "Display version of this CLI",
|
||||
Long: "Display version of this CLI.",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd.Printf("CLI Version: v%s \n", constants.VersionInfo)
|
||||
},
|
||||
Run: runVersion,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runVersion(cmd *cobra.Command, args []string) {
|
||||
buildInfo, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
cmd.Printf("Unable to retrieve build info. Is buildvcs enabled?")
|
||||
return
|
||||
}
|
||||
|
||||
commit, state, date, goVersion, compiler, platform := parseBuildInfo(buildInfo)
|
||||
|
||||
cmd.Printf("Version:\t%s\n", constants.VersionInfo)
|
||||
cmd.Printf("GitCommit:\t%s\n", commit)
|
||||
cmd.Printf("GitTreeState:\t%s\n", state)
|
||||
cmd.Printf("BuildDate:\t%s\n", date)
|
||||
cmd.Printf("GoVersion:\t%s\n", goVersion)
|
||||
cmd.Printf("Compiler:\t%s\n", compiler)
|
||||
cmd.Printf("Platform:\t%s\n", platform)
|
||||
}
|
||||
|
||||
func parseBuildInfo(info *debug.BuildInfo) (commit, state, date, goVersion, compiler, platform string) {
|
||||
var arch, os string
|
||||
for idx := range info.Settings {
|
||||
key := info.Settings[idx].Key
|
||||
value := info.Settings[idx].Value
|
||||
|
||||
switch key {
|
||||
case "-compiler":
|
||||
compiler = value
|
||||
case "GOARCH":
|
||||
arch = value
|
||||
case "GOOS":
|
||||
os = value
|
||||
case "vcs.time":
|
||||
date = value
|
||||
case "vcs.modified":
|
||||
if value == "true" {
|
||||
state = "dirty"
|
||||
} else {
|
||||
state = "clean"
|
||||
}
|
||||
case "vcs.revision":
|
||||
commit = value
|
||||
}
|
||||
}
|
||||
|
||||
platform = os + "/" + arch
|
||||
goVersion = info.GoVersion
|
||||
return commit, state, date, goVersion, compiler, platform
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue