Exemplo n.º 1
0
func versionCmd(c *commander.Command, _ []string) error {
	number := c.Flag.Lookup("number").Value.Get().(bool)
	if !number {
		u.POut("ipfs version ")
	}
	u.POut("%s\n", Version)
	return nil
}
Exemplo n.º 2
0
func refCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 {
		u.POut(c.Long)
		return nil
	}

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

	recursive := c.Flag.Lookup("r").Value.Get().(bool)
	unique := c.Flag.Lookup("u").Value.Get().(bool)
	refsSeen := map[u.Key]bool{}

	printRef := func(h mh.Multihash) {
		if unique {
			_, found := refsSeen[u.Key(h)]
			if found {
				return
			}
			refsSeen[u.Key(h)] = true
		}

		u.POut("%s\n", h.B58String())
	}

	var printRefs func(nd *mdag.Node, recursive bool)
	printRefs = func(nd *mdag.Node, recursive bool) {

		for _, link := range nd.Links {
			printRef(link.Hash)

			if recursive {
				nd, err := n.DAG.Get(u.Key(link.Hash))
				if err != nil {
					u.PErr("error: cannot retrieve %s (%s)\n", link.Hash.B58String(), err)
					return
				}

				printRefs(nd, recursive)
			}
		}
	}

	for _, fn := range inp {
		nd, err := n.Resolver.ResolvePath(fn)
		if err != nil {
			return err
		}

		printRefs(nd, recursive)
	}
	return nil
}
Exemplo n.º 3
0
func configCmd(c *commander.Command, inp []string) error {

	// todo: implement --config filename flag.
	filename, err := config.Filename("")
	if err != nil {
		return err
	}

	// if editing, open the editor
	if c.Flag.Lookup("edit").Value.Get().(bool) {
		return configEditor(filename)
	}

	// if showing, cat the file
	if c.Flag.Lookup("show").Value.Get().(bool) {
		return configCat(filename)
	}

	if len(inp) == 0 {
		// "ipfs config" run without parameters
		u.POut(c.Long)
		return nil
	}

	// Getter (1 param)
	if len(inp) == 1 {
		value, err := config.ReadConfigKey(filename, inp[0])
		if err != nil {
			return fmt.Errorf("Failed to get config value: %s", err)
		}

		strval, ok := value.(string)
		if ok {
			u.POut("%s\n", strval)
			return nil
		}

		if err := config.Encode(os.Stdout, value); err != nil {
			return fmt.Errorf("Failed to encode config value: %s", err)
		}
		u.POut("\n")
		return nil
	}

	// Setter (>1 params)
	err = config.WriteConfigKey(filename, inp[0], inp[1])
	if err != nil {
		return fmt.Errorf("Failed to set config value: %s", err)
	}

	return nil
}
Exemplo n.º 4
0
func mountCmd(c *commander.Command, inp []string) error {
	u.Debug = true
	if len(inp) < 1 || len(inp[0]) == 0 {
		u.POut(c.Long)
		return nil
	}
	fmt.Println("wtf.")

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

	fmt.Println("starting new daemon listener...")
	dl, err := daemon.NewDaemonListener(n, "localhost:12345")
	if err != nil {
		return err
	}
	go dl.Listen()
	defer dl.Close()

	mp := inp[0]
	fmt.Printf("Mounting at %s\n", mp)

	return rofs.Mount(n, mp)
}
Exemplo n.º 5
0
func catCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 {
		u.POut(c.Long)
		return nil
	}

	expanded, err := u.ExpandPathnames(inp)
	if err != nil {
		return err
	}

	com := daemon.NewCommand()
	com.Command = "cat"
	com.Args = expanded

	err = daemon.SendCommand(com, "localhost:12345")
	if err != nil {
		n, err := localNode(false)
		if err != nil {
			return err
		}

		return commands.Cat(n, com.Args, com.Opts, os.Stdout)
	}
	return nil
}
Exemplo n.º 6
0
// addNode adds the node to the graph + local storage
func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
	// add the file to the graph + local storage
	err := n.DAG.AddRecursive(nd)
	if err != nil {
		return err
	}

	u.POut("added %s\n", fpath)

	// ensure we keep it. atm no-op
	return n.PinDagNode(nd)
}
Exemplo n.º 7
0
func commandsCmd(c *commander.Command, args []string) error {
	var listCmds func(c *commander.Command)
	listCmds = func(c *commander.Command) {
		u.POut("%s\n", c.FullSpacedName())
		for _, sc := range c.Subcommands {
			listCmds(sc)
		}
	}

	listCmds(c.Parent)
	return nil
}
Exemplo n.º 8
0
func configCat(filename string) error {

	file, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer file.Close()

	if _, err = io.Copy(os.Stdout, file); err != nil {
		return err
	}
	u.POut("\n")
	return nil
}
Exemplo n.º 9
0
func copyPeersFromList(target ID, peerArr peerSorterArr, peerList *list.List) peerSorterArr {
	for e := peerList.Front(); e != nil; e = e.Next() {
		p := e.Value.(*peer.Peer)
		pID := ConvertPeerID(p.ID)
		pd := peerDistance{
			p:        p,
			distance: xor(target, pID),
		}
		peerArr = append(peerArr, &pd)
		if e == nil {
			u.POut("list element was nil.\n")
			return peerArr
		}
	}
	return peerArr
}
Exemplo n.º 10
0
func commandsHelpCmd(c *commander.Command, args []string) error {
	u.POut(referenceHeaderMsg)
	u.POut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))

	var printCmds func(*commander.Command, int)
	printCmds = func(c *commander.Command, level int) {
		u.POut("%s ", strings.Repeat("#", level))
		u.POut("%s\n\n", c.FullSpacedName())
		u.POut("```\n")
		u.POut("%s\n", c.Long)
		u.POut("```\n\n")

		for _, sc := range c.Subcommands {
			printCmds(sc, level+1)
		}
	}

	printCmds(c.Parent.Parent, 1)
	return nil
}
Exemplo n.º 11
0
Arquivo: ls.go Projeto: mappum/go-ipfs
func lsCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 {
		u.POut(c.Long)
		return nil
	}

	com := daemon.NewCommand()
	com.Command = "ls"
	com.Args = inp
	err := daemon.SendCommand(com, "localhost:12345")
	if err != nil {
		fmt.Println(err)
		n, err := localNode(false)
		if err != nil {
			return err
		}

		return commands.Ls(n, com.Args, com.Opts, os.Stdout)
	}

	return nil
}
Exemplo n.º 12
0
func addCmd(c *commander.Command, inp []string) error {
	if len(inp) < 1 {
		u.POut(c.Long)
		return nil
	}

	cmd := daemon.NewCommand()
	cmd.Command = "add"
	fmt.Println(inp)
	cmd.Args = inp
	cmd.Opts["r"] = c.Flag.Lookup("r").Value.Get()
	err := daemon.SendCommand(cmd, "localhost:12345")
	if err != nil {
		// Do locally
		n, err := localNode(false)
		if err != nil {
			return err
		}

		return commands.Add(n, cmd.Args, cmd.Opts, os.Stdout)
	}
	return nil
}
Exemplo n.º 13
0
func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
	u.POut("Pinning node. Currently No-Op\n")
	return nil
}
Exemplo n.º 14
0
func ipfsCmd(c *commander.Command, args []string) error {
	u.POut(c.Long)
	return nil
}