diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index 521f2beed..bb4c3673c 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "os" "runtime/pprof" @@ -106,17 +105,30 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) { // Gets the config "-c" flag from the command, or returns // the default configuration root directory func getConfigDir(c *commander.Command) (string, error) { - conf := c.Flag.Lookup("c").Value.Get() - if conf == nil { - return config.PathRoot() - } - confStr, ok := conf.(string) - if !ok { - return "", errors.New("failed to retrieve config flag value.") - } - if len(confStr) == 0 { - return config.PathRoot() + + // use the root cmd (that's where config is specified) + for ; c.Parent != nil; c = c.Parent { } - return u.TildeExpansion(confStr) + // flag should be defined on root. + param := c.Flag.Lookup("c").Value.Get().(string) + if param != "" { + return u.TildeExpansion(param) + } + + return config.PathRoot() +} + +func getConfig(c *commander.Command) (*config.Config, error) { + confdir, err := getConfigDir(c) + if err != nil { + return nil, err + } + + filename, err := config.Filename(confdir) + if err != nil { + return nil, err + } + + return config.Load(filename) }