cat.go 739 Bytes
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package main

import (
	"github.com/gonuts/flag"
	"github.com/jbenet/commander"
	u "github.com/jbenet/go-ipfs/util"
)

var cmdIpfsCat = &commander.Command{
	UsageLine: "cat",
	Short:     "Show ipfs object data.",
	Long: `ipfs cat <ipfs-path> - Show ipfs object data.

    Retrieves the object named by <ipfs-path> and displays the Data
    it contains.
`,
	Run:  catCmd,
	Flag: *flag.NewFlagSet("ipfs-cat", flag.ExitOnError),
}

func catCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 {
		u.POut(c.Long)
		return nil
	}

	n, err := localNode()
	if err != nil {
		return err
	}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
32
	for _, fn := range inp {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
33
		nd, err := n.Resolver.ResolvePath(fn)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34 35 36 37 38 39
		if err != nil {
			return err
		}

		u.POut("%s", nd.Data)
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
40 41
	return nil
}