mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
magellan "github.com/OpenCHAMI/magellan/internal"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version string
|
||||||
|
commit string
|
||||||
|
date string
|
||||||
|
output string
|
||||||
|
)
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if cmd.Flag("rev").Value.String() == "true" {
|
if cmd.Flag("commit").Value.String() == "true" {
|
||||||
fmt.Println(magellan.VersionCommit())
|
output = commit
|
||||||
|
if date != "" {
|
||||||
|
output += " built @ " + date
|
||||||
|
}
|
||||||
|
fmt.Println(output)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(magellan.VersionTag())
|
fmt.Println(version)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
versionCmd.Flags().Bool("rev", false, "show the version commit")
|
versionCmd.Flags().Bool("commit", false, "show the version commit")
|
||||||
rootCmd.AddCommand(versionCmd)
|
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"
|
"github.com/OpenCHAMI/magellan/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version string
|
||||||
|
commit string
|
||||||
|
date string
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
cmd.SetVersionInfo(version, commit, date)
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue