From 5ef58cadeefb884acad4b5881e2ab7015797f23f Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Sun, 5 Jul 2020 00:18:29 +0200 Subject: [PATCH] add version flag --- cmd/root.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 2f9bdf8..97f80e6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,15 +3,16 @@ package cmd import ( "crypto/tls" "fmt" - "github.com/apex/log" - "github.com/mitchellh/colorstring" - "github.com/pterodactyl/wings/loggers/cli" - "golang.org/x/crypto/acme/autocert" "net/http" "os" "path" "strings" + "github.com/apex/log" + "github.com/mitchellh/colorstring" + "github.com/pterodactyl/wings/loggers/cli" + "golang.org/x/crypto/acme/autocert" + "github.com/pkg/errors" "github.com/pkg/profile" "github.com/pterodactyl/wings/config" @@ -30,6 +31,7 @@ var debug = false var shouldRunProfiler = false var useAutomaticTls = false var tlsHostname = "" +var showVersion = false var root = &cobra.Command{ Use: "wings", @@ -41,10 +43,11 @@ var root = &cobra.Command{ os.Exit(1) } }, - Run: rootCmdRun, + Run: rootCmdRun, } func init() { + root.PersistentFlags().BoolVar(&showVersion, "version", false, "show the version and exit") root.PersistentFlags().StringVar(&configPath, "config", config.DefaultLocation, "set the location for the configuration file") root.PersistentFlags().BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode") root.PersistentFlags().BoolVar(&shouldRunProfiler, "profile", false, "pass in order to profile wings") @@ -76,6 +79,11 @@ func readConfiguration() (*config.Configuration, error) { } func rootCmdRun(*cobra.Command, []string) { + if showVersion { + fmt.Println(system.Version) + os.Exit(0) + } + if shouldRunProfiler { defer profile.Start().Stop() } @@ -229,10 +237,10 @@ func rootCmdRun(*cobra.Command, []string) { } log.WithFields(log.Fields{ - "use_ssl": c.Api.Ssl.Enabled, + "use_ssl": c.Api.Ssl.Enabled, "use_auto_tls": useAutomaticTls && len(tlsHostname) > 0, "host_address": c.Api.Host, - "host_port": c.Api.Port, + "host_port": c.Api.Port, }).Info("configuring internal webserver") r := router.Configure() @@ -240,9 +248,9 @@ func rootCmdRun(*cobra.Command, []string) { if useAutomaticTls && len(tlsHostname) > 0 { m := autocert.Manager{ - Prompt: autocert.AcceptTOS, - Cache: autocert.DirCache(path.Join(c.System.RootDirectory, "/.tls-cache")), - HostPolicy: autocert.HostWhitelist(tlsHostname), + Prompt: autocert.AcceptTOS, + Cache: autocert.DirCache(path.Join(c.System.RootDirectory, "/.tls-cache")), + HostPolicy: autocert.HostWhitelist(tlsHostname), } log.WithField("hostname", tlsHostname).