Commit 091f6f85 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

added getConfig

parent a2c2c487
package main package main
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"runtime/pprof" "runtime/pprof"
...@@ -106,17 +105,30 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) { ...@@ -106,17 +105,30 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
// Gets the config "-c" flag from the command, or returns // Gets the config "-c" flag from the command, or returns
// the default configuration root directory // the default configuration root directory
func getConfigDir(c *commander.Command) (string, error) { func getConfigDir(c *commander.Command) (string, error) {
conf := c.Flag.Lookup("c").Value.Get()
if conf == nil { // use the root cmd (that's where config is specified)
return config.PathRoot() for ; c.Parent != nil; c = c.Parent {
}
// flag should be defined on root.
param := c.Flag.Lookup("c").Value.Get().(string)
if param != "" {
return u.TildeExpansion(param)
} }
confStr, ok := conf.(string)
if !ok { return config.PathRoot()
return "", errors.New("failed to retrieve config flag value.") }
func getConfig(c *commander.Command) (*config.Config, error) {
confdir, err := getConfigDir(c)
if err != nil {
return nil, err
} }
if len(confStr) == 0 {
return config.PathRoot() filename, err := config.Filename(confdir)
if err != nil {
return nil, err
} }
return u.TildeExpansion(confStr) return config.Load(filename)
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment