1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

added getConfig

This commit is contained in:
Juan Batiz-Benet
2014-10-05 17:46:44 -07:00
parent a2c2c48773
commit 091f6f8516

View File

@ -1,7 +1,6 @@
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) {
// 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 {
}
confStr, ok := conf.(string)
if !ok {
return "", errors.New("failed to retrieve config flag value.")
}
if len(confStr) == 0 {
return config.PathRoot()
} }
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)
} }