added getConfig
Juan Batiz-Benet committed
Oct 5, 2014 at 17:46 UTC
091f6f8516cf89110db8b6153513b9e7da62a9ab
1 file changed
+22
-10
cmd/ipfs/ipfs.go
+22
-10
@@ -1,7 +1,6 @@
1
package main
2
3
import (
4
- "errors"
4
"fmt"
5
"os"
6
"runtime/pprof"
@@ -106,17 +105,30 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
105
// Gets the config "-c" flag from the command, or returns
106
// the default configuration root directory
107
func getConfigDir(c *commander.Command) (string, error) {
109
- conf := c.Flag.Lookup("c").Value.Get()
110
- if conf == nil {
111
- return config.PathRoot()
108
+
109
+ // use the root cmd (that's where config is specified)
110
+ for ; c.Parent != nil; c = c.Parent {
111
+ }
112
+
113
+ // flag should be defined on root.
114
+ param := c.Flag.Lookup("c").Value.Get().(string)
115
+ if param != "" {
116
+ return u.TildeExpansion(param)
117
}
113
- confStr, ok := conf.(string)
114
- if !ok {
115
- return "", errors.New("failed to retrieve config flag value.")
118
+
119
+ return config.PathRoot()
120
+}
121
+
122
+func getConfig(c *commander.Command) (*config.Config, error) {
123
+ confdir, err := getConfigDir(c)
124
+ if err != nil {
125
+ return nil, err
126
}
117
- if len(confStr) == 0 {
118
- return config.PathRoot()
127
+
128
+ filename, err := config.Filename(confdir)
129
+ if err != nil {
130
+ return nil, err
131
}
132
121
- return u.TildeExpansion(confStr)
133
+ return config.Load(filename)
134
}