pin.go 1.07 KB
Newer Older
1 2 3 4 5
package main

import (
	"os"

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"
	"github.com/jbenet/go-ipfs/core/commands"
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	"github.com/jbenet/go-ipfs/daemon"
	u "github.com/jbenet/go-ipfs/util"
)

var cmdIpfsPin = &commander.Command{
	UsageLine: "pin",
	Short:     "pin an ipfs object to local storage.",
	Long: `ipfs pin <ipfs-path> - pin ipfs object to local storage.

    Retrieves the object named by <ipfs-path> and stores it locally
    on disk.
`,
	Run:  pinCmd,
	Flag: *flag.NewFlagSet("ipfs-pin", flag.ExitOnError),
}

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

31 32 33
	cmd := daemon.NewCommand()
	cmd.Command = "pin"
	cmd.Args = inp
34

35
	err := daemon.SendCommand(cmd, "localhost:12345")
36
	if err != nil {
37 38 39 40 41
		conf, err := getConfigDir(c.Parent)
		if err != nil {
			return err
		}
		n, err := localNode(conf, false)
42 43 44 45
		if err != nil {
			return err
		}

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