Don't force debug to true in config file when set via flag

This commit is contained in:
Dane Everitt 2019-12-21 21:10:45 -08:00
parent 536038967a
commit a8e907a0fc
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 19 additions and 3 deletions

View File

@ -250,12 +250,17 @@ func ReadConfiguration(path string) (*Configuration, error) {
} }
var _config *Configuration var _config *Configuration
var _debugViaFlag bool
// Set the global configuration instance. // Set the global configuration instance.
func Set(c *Configuration) { func Set(c *Configuration) {
_config = c _config = c
} }
func SetDebugViaFlag(d bool) {
_debugViaFlag = d
}
// Get the global configuration instance. // Get the global configuration instance.
func Get() *Configuration { func Get() *Configuration {
return _config return _config
@ -383,7 +388,14 @@ func (c *Configuration) WriteToDisk() error {
} }
defer f.Close() defer f.Close()
b, err := yaml.Marshal(&c) ccopy := *c
// If debugging is set with the flag, don't save that to the configuration file, otherwise
// you'll always end up in debug mode.
if _debugViaFlag {
ccopy.Debug = false
}
b, err := yaml.Marshal(&ccopy)
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,11 +15,14 @@ import (
"os" "os"
) )
var configPath = "config.yml"
var debug = false
// Entrypoint for the Wings application. Configures the logger and checks any // Entrypoint for the Wings application. Configures the logger and checks any
// flags that were passed through in the boot arguments. // flags that were passed through in the boot arguments.
func main() { func main() {
var configPath = *flag.String("config", "config.yml", "set the location for the configuration file") flag.StringVar(&configPath, "config", "config.yml", "set the location for the configuration file")
var debug = *flag.Bool("debug", false, "pass in order to run wings in debug mode") flag.BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode")
flag.Parse() flag.Parse()
@ -49,6 +52,7 @@ func main() {
} }
config.Set(c) config.Set(c)
config.SetDebugViaFlag(debug)
zap.S().Infof("checking for pterodactyl system user \"%s\"", c.System.User) zap.S().Infof("checking for pterodactyl system user \"%s\"", c.System.User)
if su, err := c.EnsurePterodactylUser(); err != nil { if su, err := c.EnsurePterodactylUser(); err != nil {