diff --git a/cmd/ipfs/add.go b/cmd/ipfs/add.go index f33825594..b5c475d64 100644 --- a/cmd/ipfs/add.go +++ b/cmd/ipfs/add.go @@ -46,7 +46,10 @@ func addCmd(c *commander.Command, inp []string) error { err := daemon.SendCommand(cmd, "localhost:12345") if err != nil { // Do locally - conf := getConfig(c.Parent) + conf, err := getConfigDir(c.Parent) + if err != nil { + return err + } n, err := localNode(conf, false) if err != nil { return err diff --git a/cmd/ipfs/cat.go b/cmd/ipfs/cat.go index b155904c7..68e7daeaf 100644 --- a/cmd/ipfs/cat.go +++ b/cmd/ipfs/cat.go @@ -28,18 +28,16 @@ func catCmd(c *commander.Command, inp []string) error { return nil } - expanded, err := u.ExpandPathnames(inp) - if err != nil { - return err - } - com := daemon.NewCommand() com.Command = "cat" - com.Args = expanded + com.Args = inp - err = daemon.SendCommand(com, "localhost:12345") + err := daemon.SendCommand(com, "localhost:12345") if err != nil { - conf := getConfig(c.Parent) + conf, err := getConfigDir(c.Parent) + if err != nil { + return err + } n, err := localNode(conf, false) if err != nil { return err diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index a70e0eb81..ef5b0d18c 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -32,12 +32,27 @@ func init() { } func initCmd(c *commander.Command, inp []string) error { - filename, err := config.Filename(config.DefaultConfigFilePath) + configpath, err := getConfigDir(c.Parent) + if err != nil { + return err + } + if configpath == "" { + configpath, err = u.TildeExpansion("~/.go-ipfs") + if err != nil { + return err + } + } + + filename, err := config.Filename(configpath + "/config") if err != nil { return errors.New("Couldn't get home directory path") } + fi, err := os.Lstat(filename) - force := c.Flag.Lookup("f").Value.Get().(bool) + force, ok := c.Flag.Lookup("f").Value.Get().(bool) + if !ok { + return errors.New("failed to parse force flag") + } if fi != nil || (err != nil && !os.IsNotExist(err)) && !force { return errors.New("ipfs configuration file already exists!\nReinitializing would overwrite your keys.\n(use -f to force overwrite)") } @@ -55,7 +70,10 @@ func initCmd(c *commander.Command, inp []string) error { // This needs thought // cfg.Identity.Address = "" - nbits := c.Flag.Lookup("b").Value.Get().(int) + nbits, ok := c.Flag.Lookup("b").Value.Get().(int) + if !ok { + return errors.New("failed to get bits flag") + } if nbits < 1024 { return errors.New("Bitsize less than 1024 is considered unsafe.") } diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index b0194e74a..5e895175b 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" @@ -52,7 +53,7 @@ Use "ipfs help " for more information about a command. } func init() { - CmdIpfs.Flag.String("c", "~/.go-ipfs/config", "specify config file") + CmdIpfs.Flag.String("c", config.DefaultPathRoot, "specify config directory") } func ipfsCmd(c *commander.Command, args []string) error { @@ -72,9 +73,8 @@ func main() { return } -func localNode(conf string, online bool) (*core.IpfsNode, error) { - //todo implement config file flag - cfg, err := config.Load(conf) +func localNode(confdir string, online bool) (*core.IpfsNode, error) { + cfg, err := config.Load(confdir + "/config") if err != nil { return nil, err } @@ -84,11 +84,14 @@ func localNode(conf string, online bool) (*core.IpfsNode, error) { // Gets the config "-c" flag from the command, or returns // the empty string -func getConfig(c *commander.Command) string { +func getConfigDir(c *commander.Command) (string, error) { conf := c.Flag.Lookup("c").Value.Get() - confStr, ok := conf.(string) - if ok { - return confStr + if conf == nil { + return "", nil } - return "" + confStr, ok := conf.(string) + if !ok { + return "", errors.New("failed to retrieve config flag value.") + } + return confStr, nil } diff --git a/cmd/ipfs/ls.go b/cmd/ipfs/ls.go index d654a34dd..59c7ee10c 100644 --- a/cmd/ipfs/ls.go +++ b/cmd/ipfs/ls.go @@ -36,7 +36,10 @@ func lsCmd(c *commander.Command, inp []string) error { com.Args = inp err := daemon.SendCommand(com, "localhost:12345") if err != nil { - conf := getConfig(c.Parent) + conf, err := getConfigDir(c.Parent) + if err != nil { + return err + } n, err := localNode(conf, false) if err != nil { return err diff --git a/cmd/ipfs/mount_unix.go b/cmd/ipfs/mount_unix.go index 0626a7183..92d445395 100644 --- a/cmd/ipfs/mount_unix.go +++ b/cmd/ipfs/mount_unix.go @@ -33,7 +33,10 @@ func mountCmd(c *commander.Command, inp []string) error { return nil } - conf := getConfig(c.Parent) + conf, err := getConfigDir(c.Parent) + if err != nil { + return err + } n, err := localNode(conf, true) if err != nil { return err diff --git a/cmd/ipfs/refs.go b/cmd/ipfs/refs.go index 5429d9da1..ce45b29f0 100644 --- a/cmd/ipfs/refs.go +++ b/cmd/ipfs/refs.go @@ -46,7 +46,10 @@ func refCmd(c *commander.Command, inp []string) error { err := daemon.SendCommand(cmd, "localhost:12345") if err != nil { // Do locally - conf := getConfig(c.Parent) + conf, err := getConfigDir(c.Parent) + if err != nil { + return err + } n, err := localNode(conf, false) if err != nil { return err