Update for recent go-flags API changes.

This commit is contained in:
Dave Collins 2013-11-24 12:33:36 -06:00
parent 6f2b96b7e2
commit 8e3ede441b
2 changed files with 12 additions and 3 deletions

View file

@ -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 " +

View file

@ -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)