cat.go 1.05 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3
package main

import (
4
	"os"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
5

6 7
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
	"github.com/jbenet/go-ipfs/core/commands"
9
	"github.com/jbenet/go-ipfs/daemon"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	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
	}

31 32
	com := daemon.NewCommand()
	com.Command = "cat"
33
	com.Args = inp
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34

35
	err := daemon.SendCommand(com, "localhost:12345")
36
	if err != nil {
37 38 39 40
		conf, err := getConfigDir(c.Parent)
		if err != nil {
			return err
		}
Jeromy's avatar
Jeromy committed
41
		n, err := localNode(conf, false)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
42 43 44 45
		if err != nil {
			return err
		}

46
		return commands.Cat(n, com.Args, com.Opts, os.Stdout)
47 48 49
	}
	return nil
}