decred.org/dcrdex@v1.0.5/client/cmd/bisonw/config.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "runtime" 7 8 "decred.org/dcrdex/client/app" 9 ) 10 11 func configure() (*app.Config, error) { 12 // Pre-parse the command line options to see if an alternative config file 13 // or the version flag was specified. Override any environment variables 14 // with parsed command line flags. 15 iniCfg := app.DefaultConfig 16 preCfg := iniCfg 17 if err := app.ParseCLIConfig(&preCfg); err != nil { 18 return nil, err 19 } 20 21 // Show the version and exit if the version flag was specified. 22 if preCfg.ShowVer { 23 fmt.Printf("%s version %s (Go version %s %s/%s)\n", 24 appName, app.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH) 25 os.Exit(0) 26 } 27 28 appData, configPath := app.ResolveCLIConfigPaths(&preCfg) 29 30 // Load additional config from file. 31 if err := app.ParseFileConfig(configPath, &iniCfg); err != nil { 32 return nil, err 33 } 34 // cfg.AppData is now re-parsed from CLI, so we need to use appData. 35 36 cfg := &iniCfg 37 return cfg, app.ResolveConfig(appData, cfg) 38 }