ls.go 976 Bytes
Newer Older
1 2 3
package main

import (
4 5 6
	"fmt"
	"os"

7 8
	"github.com/gonuts/flag"
	"github.com/jbenet/commander"
9
	"github.com/jbenet/go-ipfs/daemon"
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	u "github.com/jbenet/go-ipfs/util"
)

var cmdIpfsLs = &commander.Command{
	UsageLine: "ls",
	Short:     "List links from an object.",
	Long: `ipfs ls <ipfs-path> - List links from an object.

    Retrieves the object named by <ipfs-path> and displays the links
    it contains, with the following format:

    <link base58 hash> <link size in bytes> <link name>

`,
	Run:  lsCmd,
	Flag: *flag.NewFlagSet("ipfs-ls", flag.ExitOnError),
}

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

34 35 36 37 38
	fmt.Println("hello")
	com := daemon.NewCommand()
	com.Command = "ls"
	com.Args = inp
	err := daemon.SendCommand(com, "localhost:12345")
39
	if err != nil {
40 41
		fmt.Println(err)
		n, err := localNode(false)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
42 43 44 45
		if err != nil {
			return err
		}

46
		daemon.ExecuteCommand(com, n, os.Stdout)
47
	}
48

49 50
	return nil
}