Skip to content

Commit

Permalink
nit fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
root-hbx committed Nov 23, 2024
1 parent fd7fa9e commit ca07649
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,47 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
"runtime/debug"

"github.com/microsoft/retina/internal/buildinfo"
"github.com/spf13/cobra"
)

var version = &cobra.Command{
Use: "version",
Short: "Show version",
Run: func(*cobra.Command, []string) {
fmt.Println(buildinfo.Version)
Run: func(cmd *cobra.Command, args []string) {
// Version is fetched from buildinfo package.
if buildinfo.Version != "" {
fmt.Println(buildinfo.Version)
return
}

// Fetch version from Build Settings.
const baseLine = "buildinfo.Version is not set successfully"

info, ok := debug.ReadBuildInfo()
if !ok {
fmt.Printf("%s, and BuildInfo is not available\n", baseLine)
return
}

var revision string
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
revision = setting.Value
break
}
}

// If revision is available, show it.
if revision != "" {
fmt.Printf("%s, showing vcs.revision: %s\n", baseLine, revision)
return
}

// Revision is not available, raise error.
fmt.Printf("%s, and vcs.revision is not available\n", baseLine)
},
}

Expand Down

0 comments on commit ca07649

Please sign in to comment.