mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
added getConfig
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user