From 8e3ede441b49106f51062c278ce7fd03c745f81a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 24 Nov 2013 12:33:36 -0600 Subject: [PATCH] Update for recent go-flags API changes. --- config.go | 13 +++++++++++-- util/btcctl/config.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index acd72c70..f61a0a48 100644 --- a/config.go +++ b/config.go @@ -275,16 +275,17 @@ func loadConfig() (*config, []string, error) { } // Load additional config from file. + var configFileError error parser := flags.NewParser(&cfg, flags.Default) if !preCfg.RegressionTest || preCfg.ConfigFile != defaultConfigFile { - err := parser.ParseIniFile(preCfg.ConfigFile) + err := flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile) if err != nil { if _, ok := err.(*os.PathError); !ok { fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err } - btcdLog.Warnf("%v", err) + configFileError = err } } @@ -302,6 +303,14 @@ func loadConfig() (*config, []string, error) { return nil, nil, err } + // Warn about missing config file after the final command line parse + // succeeds. This prevents the warning on help messages and invalid + // options. + if configFileError != nil { + btcdLog.Warnf("%v", configFileError) + } + + // The two test networks can't be selected simultaneously. if cfg.TestNet3 && cfg.RegressionTest { str := "%s: The testnet and regtest params can't be used " + diff --git a/util/btcctl/config.go b/util/btcctl/config.go index 95dc3f8b..6ab3be88 100644 --- a/util/btcctl/config.go +++ b/util/btcctl/config.go @@ -73,7 +73,7 @@ func loadConfig() (*flags.Parser, *config, []string, error) { // Load additional config from file. parser := flags.NewParser(&cfg, flags.PassDoubleDash|flags.HelpFlag) - err = parser.ParseIniFile(preCfg.ConfigFile) + err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile) if err != nil { if _, ok := err.(*os.PathError); !ok { fmt.Fprintln(os.Stderr, err)