resolve.go 565 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package commands

import (
	"errors"
	"fmt"
	"io"

	"github.com/jbenet/go-ipfs/core"
)

func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {

	name := ""

	switch len(args) {
	case 1:
		name = args[0]
	case 0:
		if n.Identity == nil {
			return errors.New("Identity not loaded!")
		}
		name = n.Identity.ID().String()

	default:
		return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
	}

	res, err := n.Namesys.Resolve(name)
	if err != nil {
		return err
	}

	fmt.Fprintf(out, "%s\n", res)
	return nil
}