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

added getConfig

parent a2c2c487
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()
// use the root cmd (that's where config is specified)
for ; c.Parent != nil; c = c.Parent {
}
confStr, ok := conf.(string)
if !ok {
return "", errors.New("failed to retrieve config flag value.")
// flag should be defined on root.
param := c.Flag.Lookup("c").Value.Get().(string)
if param != "" {
return u.TildeExpansion(param)
}
if len(confStr) == 0 {
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 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