diff --git a/cmd/root.go b/cmd/root.go index fda49b6..5868e62 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,6 +30,7 @@ var log = logrus.New() var ( cfgFile string logLevel string + Version string ) // RootCmd represents the base command when called without any subcommands diff --git a/cmd/version.go b/cmd/version.go index 6098f4d..9cb124e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -25,7 +25,7 @@ var versionCmd = &cobra.Command{ Short: "Print the version number of php-fpm_exporter", Long: `All software has versions. This is php-fpm_exporter's'`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("php-fpm_exporter v0.9 -- HEAD") + fmt.Printf("php-fpm_exporter %v\n", Version) }, } diff --git a/main.go b/main.go index 309852e..8fffe69 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,18 @@ package main -import "github.com/hipages/php-fpm_exporter/cmd" +import ( + "fmt" + "github.com/hipages/php-fpm_exporter/cmd" +) + +var ( + version = "dev" + commit = "none" + date = "unknown" +) func main() { + cmd.Version = fmt.Sprintf("%v, commit %v, built at %v", version, commit, date) cmd.Execute() }