add version flag

This commit is contained in:
Adora Laura Kalb 2024-07-26 10:54:33 +02:00
parent 6a0644d9af
commit d2748259cb
Signed by: adoralaura
SSH key fingerprint: SHA256:3XrkbR8ikAZJVtYfaUliX1MhmJYVAe/ocIb/MiDHBJ8

View file

@ -17,14 +17,23 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
var Version string
func main() { func main() {
quiet := pflag.BoolP("quiet", "q", false, "Disable logging") quietFlag := pflag.BoolP("quiet", "q", false, "Disable logging")
verbose := pflag.Bool("debug", false, "Enable debug logging (beats --quiet)") verboseFlag := pflag.Bool("debug", false, "Enable debug logging (beats --quiet)")
versionFlag := pflag.BoolP("version", "v", false, "Show version information")
pflag.BoolVarP(&configuration.DryRun, "dry-run", "d", false, "Show what this application *would* do") pflag.BoolVarP(&configuration.DryRun, "dry-run", "d", false, "Show what this application *would* do")
pflag.StringVarP(&configuration.ConfigFile, "config", "c", "", "Path to config file (default: $WorkDir/config.yaml)") pflag.StringVarP(&configuration.ConfigFile, "config", "c", "", "Path to config file (default: $WorkDir/config.yaml)")
pflag.Parse() pflag.Parse()
logging.NewSlogLogger(*quiet, *verbose)
if *versionFlag {
fmt.Println("mailcow-admin-aliases " + Version)
return
}
logging.NewSlogLogger(*quietFlag, *verboseFlag)
var cfg configuration.Config var cfg configuration.Config
err := cfg.LoadFromDisk() err := cfg.LoadFromDisk()