Commit ec40a29b authored by Jeromy's avatar Jeromy

change ExecuteCommand to return an error

parent 80dc4b35
...@@ -50,7 +50,10 @@ func addCmd(c *commander.Command, inp []string) error { ...@@ -50,7 +50,10 @@ func addCmd(c *commander.Command, inp []string) error {
return err return err
} }
daemon.ExecuteCommand(cmd, n, os.Stdout) err := daemon.ExecuteCommand(cmd, n, os.Stdout)
if err != nil {
fmt.Println(err)
}
} }
return nil return nil
} }
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
...@@ -38,7 +39,10 @@ func catCmd(c *commander.Command, inp []string) error { ...@@ -38,7 +39,10 @@ func catCmd(c *commander.Command, inp []string) error {
return err return err
} }
daemon.ExecuteCommand(com, n, os.Stdout) err := daemon.ExecuteCommand(com, n, os.Stdout)
if err != nil {
fmt.Println(err)
}
} }
return nil return nil
} }
...@@ -42,7 +42,10 @@ func lsCmd(c *commander.Command, inp []string) error { ...@@ -42,7 +42,10 @@ func lsCmd(c *commander.Command, inp []string) error {
return err return err
} }
daemon.ExecuteCommand(com, n, os.Stdout) err := daemon.ExecuteCommand(com, n, os.Stdout)
if err != nil {
fmt.Println(err)
}
} }
return nil return nil
......
...@@ -74,10 +74,13 @@ func (dl *DaemonListener) handleConnection(conn net.Conn) { ...@@ -74,10 +74,13 @@ func (dl *DaemonListener) handleConnection(conn net.Conn) {
} }
u.DOut("Got command: %v\n", command) u.DOut("Got command: %v\n", command)
ExecuteCommand(&command, dl.node, conn) err := ExecuteCommand(&command, dl.node, conn)
if err != nil {
fmt.Fprintln(conn, "%v\n", err)
}
} }
func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) { func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) error {
u.DOut("executing command: %s\n", com.Command) u.DOut("executing command: %s\n", com.Command)
switch com.Command { switch com.Command {
case "add": case "add":
...@@ -86,38 +89,40 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) { ...@@ -86,38 +89,40 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) {
depth = -1 depth = -1
} }
for _, path := range com.Args { for _, path := range com.Args {
_, err := commands.AddPath(ipfsnode, path, depth) nd, err := commands.AddPath(ipfsnode, path, depth)
if err != nil {
return fmt.Errorf("addFile error: %v", err)
}
k, err := nd.Key()
if err != nil { if err != nil {
fmt.Fprintf(out, "addFile error: %v\n", err) return fmt.Errorf("addFile error: %v", err)
continue
} }
fmt.Fprintf(out, "Added node: %s = %s\n", path, k.Pretty())
} }
case "cat": case "cat":
for _, fn := range com.Args { for _, fn := range com.Args {
dagnode, err := ipfsnode.Resolver.ResolvePath(fn) dagnode, err := ipfsnode.Resolver.ResolvePath(fn)
if err != nil { if err != nil {
fmt.Fprintf(out, "catFile error: %v\n", err) return fmt.Errorf("catFile error: %v", err)
return
} }
read, err := dag.NewDagReader(dagnode, ipfsnode.DAG) read, err := dag.NewDagReader(dagnode, ipfsnode.DAG)
if err != nil { if err != nil {
fmt.Fprintln(out, err) return fmt.Errorf("cat error: %v", err)
continue
} }
_, err = io.Copy(out, read) _, err = io.Copy(out, read)
if err != nil { if err != nil {
fmt.Fprintln(out, err) return fmt.Errorf("cat error: %v", err)
continue
} }
} }
case "ls": case "ls":
for _, fn := range com.Args { for _, fn := range com.Args {
dagnode, err := ipfsnode.Resolver.ResolvePath(fn) dagnode, err := ipfsnode.Resolver.ResolvePath(fn)
if err != nil { if err != nil {
fmt.Fprintf(out, "ls error: %v\n", err) return fmt.Errorf("ls error: %v", err)
return
} }
for _, link := range dagnode.Links { for _, link := range dagnode.Links {
...@@ -128,18 +133,16 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) { ...@@ -128,18 +133,16 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) {
for _, fn := range com.Args { for _, fn := range com.Args {
dagnode, err := ipfsnode.Resolver.ResolvePath(fn) dagnode, err := ipfsnode.Resolver.ResolvePath(fn)
if err != nil { if err != nil {
fmt.Fprintf(out, "pin error: %v\n", err) return fmt.Errorf("pin error: %v", err)
return
} }
err = ipfsnode.PinDagNode(dagnode) err = ipfsnode.PinDagNode(dagnode)
if err != nil { if err != nil {
fmt.Fprintf(out, "pin: %v\n", err) return fmt.Errorf("pin: %v", err)
return
} }
} }
default: default:
fmt.Fprintf(out, "Invalid Command: '%s'\n", com.Command) return fmt.Errord("Invalid Command: '%s'", com.Command)
} }
} }
......
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