diff --git a/cmd/version.go b/cmd/version.go index be17843..3ffff17 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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 +} diff --git a/main.go b/main.go index ebe2d95..0d248c4 100644 --- a/main.go +++ b/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() }