fix(config): Always show config file name and abort if read fails (#46)

With this change you should always know what config tube is using.
If an explicitly requested file can not be read, then tube
will complain and exit.

This should fix issue #45

Reviewed-on: https://git.mills.io/prologic/tube/pulls/46
Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
Heinrich 'Henrik' Langos 2023-01-05 12:27:42 +00:00 committed by James Mills
parent d0727c2187
commit f6dedea101

View file

@ -41,14 +41,15 @@ func main() {
} }
cfg := app.DefaultConfig() cfg := app.DefaultConfig()
log.Infof("Reading configuration from %s", config)
err := cfg.ReadFile(config) err := cfg.ReadFile(config)
if err == nil { if err != nil {
log.Infof("reading configuration from %s", config) if flag.Lookup("config").Changed {
} else {
if !os.IsNotExist(err) {
log.Fatal(err) log.Fatal(err)
} }
log.Infof("Reading %s failed. Starting with builtin defaults.", config)
} }
// I'd like to add something like this here: log.Debug("Active config: %s", cfg.toJson())
a, err := app.NewApp(cfg) a, err := app.NewApp(cfg)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)