refactor(init) extract force flag
Brian Tiger Chow committed
Nov 4, 2014 at 03:45 UTC
630b88d227fbbf3f0af9faa18af86b3666e6f833
1 file changed
+10
-9
cmd/ipfs2/init.go
+10
-9
@@ -29,13 +29,20 @@ var initCmd = &cmds.Command{
29
Run: func(res cmds.Response, req cmds.Request) {
30
31
arg, found := req.Option("d")
32
- dspath, ok := arg.(string) // TODO param
32
+ dspath, ok := arg.(string)
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)
38
+ arg, found = req.Option("f")
39
+ force, ok := arg.(bool) // TODO param
40
+ if found && !ok {
41
+ res.SetError(errors.New("failed to parse force flag"), cmds.ErrNormal)
42
+ return
43
+ }
44
+
45
+ err := foo(res, req, dspath, force)
46
if err != nil {
47
res.SetError(err, cmds.ErrNormal)
48
return
@@ -43,7 +50,7 @@ var initCmd = &cmds.Command{
50
},
51
}
52
46
-func foo(res cmds.Response, req cmds.Request, dspath string) error {
53
+func foo(res cmds.Response, req cmds.Request, dspath string, force bool) error {
54
ctx := req.Context()
55
56
u.POut("initializing ipfs node at %s\n", ctx.ConfigRoot)
@@ -52,12 +59,6 @@ func foo(res cmds.Response, req cmds.Request, dspath string) error {
59
return errors.New("Couldn't get home directory path")
60
}
61
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
-
62
fi, err := os.Lstat(filename)
63
if fi != nil || (err != nil && !os.IsNotExist(err)) {
64
if !force {