mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
The application version can be then displayed in the vmui. Showing the application version in vmui should make it easier to determine currently used VM version (at least vmselect version). ------------ @Loori-R it would be could to add the app version in vmui in a follow-up PR or by pushing a commit to this branch. Signed-off-by: hagen1778 <roman@victoriametrics.com>
41 lines
694 B
Go
41 lines
694 B
Go
package buildinfo
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"regexp"
|
|
)
|
|
|
|
var version = flag.Bool("version", false, "Show VictoriaMetrics version")
|
|
|
|
// Version must be set via -ldflags '-X'
|
|
var Version string
|
|
|
|
var shortVersionRe = regexp.MustCompile(`v\d+\.\d+\.\d+(?:-enterprise)?(?:-cluster)?`)
|
|
|
|
// ShortVersion returns a shortened version
|
|
func ShortVersion() string {
|
|
return shortVersionRe.FindString(Version)
|
|
}
|
|
|
|
// Init must be called after flag.Parse call.
|
|
func Init() {
|
|
if *version {
|
|
printVersion()
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
oldUsage := flag.Usage
|
|
flag.Usage = func() {
|
|
printVersion()
|
|
oldUsage()
|
|
}
|
|
}
|
|
|
|
func printVersion() {
|
|
fmt.Fprintf(flag.CommandLine.Output(), "%s\n", Version)
|
|
}
|