refactor(init) extract dspath
Brian Tiger Chow committed
Nov 4, 2014 at 03:43 UTC
b987c99eeac0050ac7e4a3343ce2118e0ab3bc61
1 file changed
+14
-11
cmd/ipfs2/init.go
+14
-11
@@ -27,7 +27,15 @@ var initCmd = &cmds.Command{
27
new keypair.
28
`,
29
Run: func(res cmds.Response, req cmds.Request) {
30
- err := foo(res, req)
30
+
31
+ arg, found := req.Option("d")
32
+ dspath, ok := arg.(string) // TODO param
33
+ if found && !ok {
34
+ res.SetError(errors.New("failed to parse datastore flag"), cmds.ErrNormal)
35
+ return
36
+ }
37
+
38
+ err := foo(res, req, dspath)
39
if err != nil {
40
res.SetError(err, cmds.ErrNormal)
41
return
@@ -35,7 +43,7 @@ var initCmd = &cmds.Command{
43
},
44
}
45
38
-func foo(res cmds.Response, req cmds.Request) error {
46
+func foo(res cmds.Response, req cmds.Request, dspath string) error {
47
ctx := req.Context()
48
49
u.POut("initializing ipfs node at %s\n", ctx.ConfigRoot)
@@ -44,17 +52,12 @@ func foo(res cmds.Response, req cmds.Request) error {
52
return errors.New("Couldn't get home directory path")
53
}
54
47
- arg, found := req.Option("d")
48
- dspath, ok := arg.(string)
49
- if found && !ok {
50
- return errors.New("failed to parse datastore flag")
51
- }
52
-
53
- arg, found = req.Option("f")
54
- force, ok := arg.(bool)
55
+ arg, found := req.Option("f")
56
+ force, ok := arg.(bool) // TODO param
57
if found && !ok {
58
return errors.New("failed to parse force flag")
59
}
60
+
61
fi, err := os.Lstat(filename)
62
if fi != nil || (err != nil && !os.IsNotExist(err)) {
63
if !force {
@@ -101,7 +104,7 @@ func foo(res cmds.Response, req cmds.Request) error {
104
}
105
106
arg, found = req.Option("b")
104
- nbits, ok := arg.(int)
107
+ nbits, ok := arg.(int) // TODO param
108
if found && !ok {
109
return errors.New("failed to get bits flag")
110
} else if !found {