mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Updated version command and main to handle building with version info
This commit is contained in:
parent
1e1498206e
commit
b4efe756b0
2 changed files with 28 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
7
main.go
7
main.go
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue