diff --git a/cmd/root.go b/cmd/root.go index 3bffd86..e29fd3b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,11 +16,9 @@ import ( "github.com/spf13/viper" ) -var VERSION = "unreleased" - var cfgFile string -var RootCmd = &cobra.Command{Use: "clisso", Version: VERSION} +var RootCmd = &cobra.Command{Use: "clisso", Version: "0.0.0"} const usageTemplate = `Usage:{{if .Runnable}} {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} @@ -73,8 +71,10 @@ func init() { RootCmd.SetVersionTemplate(versionTemplate) } -func Execute(version string) { - VERSION = version +func Execute(version, commit, date string) { + // transfer version from main to cmd + // format as "0.0.0 (commit date)" + RootCmd.Version = version + " (" + commit + " " + date + ")" err := RootCmd.Execute() if err != nil { log.Fatalf("Failed to execute: %v", err) diff --git a/main.go b/main.go index 71d9ce5..f299b1a 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,11 @@ import ( ) // This variable is used by the "version" command and is set during build. -var version = "undefined" +var ( + version = "dev" + commit = "none" + date = "unknown" +) func main() { log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) @@ -25,5 +29,5 @@ func main() { log.SetOutput(colorable.NewColorableStdout()) } - cmd.Execute(version) + cmd.Execute(version, commit, date) }