Updated version command and main to handle building with version info

This commit is contained in:
David Allen 2024-08-28 13:19:21 -06:00
parent 1e1498206e
commit b4efe756b0
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
2 changed files with 28 additions and 5 deletions

View file

@ -3,22 +3,38 @@ package cmd
import (
"fmt"
magellan "github.com/OpenCHAMI/magellan/internal"
"github.com/spf13/cobra"
)
var (
version string
commit string
date string
output string
)
var versionCmd = &cobra.Command{
Use: "version",
Run: func(cmd *cobra.Command, args []string) {
if cmd.Flag("rev").Value.String() == "true" {
fmt.Println(magellan.VersionCommit())
if cmd.Flag("commit").Value.String() == "true" {
output = commit
if date != "" {
output += " built @ " + date
}
fmt.Println(output)
} else {
fmt.Println(magellan.VersionTag())
fmt.Println(version)
}
},
}
func init() {
versionCmd.Flags().Bool("rev", false, "show the version commit")
versionCmd.Flags().Bool("commit", false, "show the version commit")
rootCmd.AddCommand(versionCmd)
}
func SetVersionInfo(buildVersion string, buildCommit string, buildDate string) {
version = buildVersion
commit = buildCommit
date = buildDate
}

View file

@ -4,6 +4,13 @@ import (
"github.com/OpenCHAMI/magellan/cmd"
)
var (
version string
commit string
date string
)
func main() {
cmd.SetVersionInfo(version, commit, date)
cmd.Execute()
}