Support --version

refs #335
This commit is contained in:
Alexander A. Klimov 2021-08-05 13:07:59 +02:00
parent b5b169aea8
commit 31fd1963f2
3 changed files with 13 additions and 0 deletions

View file

@ -1,12 +1,15 @@
package command
import (
"fmt"
"github.com/icinga/icingadb/internal"
"github.com/icinga/icingadb/pkg/config"
"github.com/icinga/icingadb/pkg/icingadb"
"github.com/icinga/icingadb/pkg/icingaredis"
"github.com/icinga/icingadb/pkg/utils"
"github.com/pkg/errors"
"go.uber.org/zap"
"os"
)
type Command struct {
@ -21,6 +24,11 @@ func New() *Command {
utils.Fatal(err)
}
if flags.Version {
fmt.Println("Icinga DB version:", internal.Version)
os.Exit(0)
}
cfg, err := config.FromYAMLFile(flags.Config)
if err != nil {
utils.Fatal(err)

3
internal/version.go Normal file
View file

@ -0,0 +1,3 @@
package internal
var Version = "v1.0.0-rc2-dev"

View file

@ -15,6 +15,8 @@ type Config struct {
// Flags defines CLI flags.
type Flags struct {
// Version decides whether to just print the version and exit.
Version bool `long:"version" description:"print version and exit"`
// Config is the path to the config file
Config string `short:"c" long:"config" description:"path to config file" required:"true" default:"./config.yml"`
// Datadir is the location of the data directory