Commit 2607bee4 authored by Jeromy's avatar Jeromy

Change config flag to accept config dir instead of file path

parent 9e4b8586
......@@ -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
......
......@@ -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
......
......@@ -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.")
}
......
package main
import (
"errors"
"fmt"
"os"
......@@ -52,7 +53,7 @@ Use "ipfs help <command>" 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()
if conf == nil {
return "", nil
}
confStr, ok := conf.(string)
if ok {
return confStr
if !ok {
return "", errors.New("failed to retrieve config flag value.")
}
return ""
return confStr, nil
}
......@@ -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
......
......@@ -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
......
......@@ -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
......
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