Skip to content

Commit

Permalink
core/commands: Added 'cat' command
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Oct 29, 2014
1 parent 3669dc3 commit d061e36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/commands/cat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

import (
"fmt"
"io"

cmds "github.com/jbenet/go-ipfs/commands"
uio "github.com/jbenet/go-ipfs/unixfs/io"
)

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()))

for _, path := range req.Arguments() {
dagnode, err := node.Resolver.ResolvePath(path)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

read, err := uio.NewDagReader(dagnode, node.DAG)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

readers = append(readers, read)
}

reader := io.MultiReader(readers...)
res.SetValue(reader)
},
}
4 changes: 4 additions & 0 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit d061e36

Please sign in to comment.