Commit 630b88d2 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

refactor(init) extract force flag

parent b987c99e
......@@ -29,13 +29,20 @@ var initCmd = &cmds.Command{
Run: func(res cmds.Response, req cmds.Request) {
arg, found := req.Option("d")
dspath, ok := arg.(string) // TODO param
dspath, ok := arg.(string)
if found && !ok {
res.SetError(errors.New("failed to parse datastore flag"), cmds.ErrNormal)
return
}
err := foo(res, req, dspath)
arg, found = req.Option("f")
force, ok := arg.(bool) // TODO param
if found && !ok {
res.SetError(errors.New("failed to parse force flag"), cmds.ErrNormal)
return
}
err := foo(res, req, dspath, force)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......@@ -43,7 +50,7 @@ var initCmd = &cmds.Command{
},
}
func foo(res cmds.Response, req cmds.Request, dspath string) error {
func foo(res cmds.Response, req cmds.Request, dspath string, force bool) error {
ctx := req.Context()
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 {
return errors.New("Couldn't get home directory path")
}
arg, found := req.Option("f")
force, ok := arg.(bool) // TODO param
if found && !ok {
return errors.New("failed to parse force flag")
}
fi, err := os.Lstat(filename)
if fi != nil || (err != nil && !os.IsNotExist(err)) {
if !force {
......
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