Commit afd8fadb authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

core/commands: Added 'cat' command

parent aea52132
......@@ -4,26 +4,34 @@ import (
"fmt"
"io"
"github.com/jbenet/go-ipfs/core"
cmds "github.com/jbenet/go-ipfs/commands"
uio "github.com/jbenet/go-ipfs/unixfs/io"
)
func Cat(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
for _, fn := range args {
dagnode, err := n.Resolver.ResolvePath(fn)
if err != nil {
return fmt.Errorf("catFile error: %v", err)
}
var cat = &cmds.Command{
Help: "TODO",
Run: func(req cmds.Request, res cmds.Response) {
node := req.Context().Node
fmt.Println(node.Resolver)
readers := make([]io.Reader, 0, len(req.Arguments()))
read, err := uio.NewDagReader(dagnode, n.DAG)
if err != nil {
return fmt.Errorf("cat error: %v", err)
}
for _, path := range req.Arguments() {
dagnode, err := node.Resolver.ResolvePath(path)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
_, err = io.Copy(out, read)
if err != nil {
return fmt.Errorf("cat error: %v", err)
read, err := uio.NewDagReader(dagnode, node.DAG)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
readers = append(readers, read)
}
}
return nil
reader := io.MultiReader(readers...)
res.SetValue(reader)
},
}
......@@ -43,6 +43,10 @@ Advanced Commands:
Use "ipfs help <command>" for more information about a command.
`,
Subcommands: map[string]*cmds.Command{
"cat": cat,
// test subcommands
// TODO: remove these when we don't need them anymore
"beep": &cmds.Command{
Run: func(req cmds.Request, res cmds.Response) {
v := &TestOutput{"hello, world", 1337}
......
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