Config: refactor config file loaders (#577)

* Config: fix don't create empty dir when resolving path

* Config: refactor config file loaders

* add a layer of abstraction so that config can be loaded from non-files
* use io.Reader / io.Writer abstraction to separate data operations from
file operations
* remove dryrun option from SaveConfig - now it always saves

* rename read and save methods to mention file operations

* log error when encryption prompt fails

* as the user didn't make a choice, we'd prompt again next time the file
is loaded
* add file.Writer tests
* skip permissions test for windows

* defer creating the writer on save to the last moment

* this avoids truncating file when there is error with password prompt
* add a test

* tests with StdIn cannot run in parallel
This commit is contained in:
Rauno Ots
2020-11-04 01:46:13 +01:00
committed by GitHub
parent 80bc8c7e9e
commit ee55ae5d0f
9 changed files with 397 additions and 128 deletions

View File

@@ -104,7 +104,7 @@ func loadConfigWithSettings(settings *Settings, flagSet map[string]bool) (*confi
log.Printf("Loading config file %s..\n", filePath)
conf := &config.Cfg
err = conf.ReadConfig(filePath, settings.EnableDryRun)
err = conf.ReadConfigFromFile(filePath, settings.EnableDryRun)
if err != nil {
return nil, fmt.Errorf(config.ErrFailureOpeningConfig, filePath, err)
}
@@ -541,7 +541,7 @@ func (bot *Engine) Stop() {
}
if !bot.Settings.EnableDryRun {
err := bot.Config.SaveConfig(bot.Settings.ConfigFile, false)
err := bot.Config.SaveConfigToFile(bot.Settings.ConfigFile)
if err != nil {
gctlog.Errorln(gctlog.Global, "Unable to save config.")
} else {