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

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

7 8
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
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 33
	com := daemon.NewCommand()
	com.Command = "cat"
	com.Args = inp
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34

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

42 43 44 45
		err := daemon.ExecuteCommand(com, n, os.Stdout)
		if err != nil {
			fmt.Println(err)
		}
46 47 48
	}
	return nil
}