diff --git a/core/commands2/resolve.go b/core/commands2/resolve.go index f6bf8f5b8..07d4a8f53 100644 --- a/core/commands2/resolve.go +++ b/core/commands2/resolve.go @@ -4,13 +4,8 @@ import ( "errors" cmds "github.com/jbenet/go-ipfs/commands" - core "github.com/jbenet/go-ipfs/core" ) -type ResolveOutput struct { - Entries []IpnsEntry -} - var resolveCmd = &cmds.Command{ Description: "Gets the value currently published at an IPNS name", Help: `IPNS is a PKI namespace, where names are the hashes of public keys, and @@ -33,13 +28,13 @@ Resolve te value of another name: `, Arguments: []cmds.Argument{ - cmds.Argument{"name", cmds.ArgString, false, true, + cmds.Argument{"name", cmds.ArgString, false, false, "The IPNS name to resolve. Defaults to your node's peerID."}, }, Run: func(res cmds.Response, req cmds.Request) { n := req.Context().Node - var names []string + var name string if n.Network == nil { res.SetError(errNotOnline, cmds.ErrNormal) @@ -51,40 +46,29 @@ Resolve te value of another name: res.SetError(errors.New("Identity not loaded!"), cmds.ErrNormal) return } - names = append(names, n.Identity.ID().String()) + name = n.Identity.ID().String() + } else { - for _, arg := range req.Arguments() { - name, ok := arg.(string) - if !ok { - res.SetError(errors.New("cast error"), cmds.ErrNormal) - return - } - names = append(names, name) + var ok bool + name, ok = req.Arguments()[0].(string) + if !ok { + res.SetError(errors.New("cast error"), cmds.ErrNormal) + return } } - entries, err := resolve(n, names) + output, err := n.Namesys.Resolve(name) if err != nil { res.SetError(err, cmds.ErrNormal) return } - res.SetOutput(&ResolveOutput{entries}) + res.SetOutput(output) + }, + Marshallers: map[cmds.EncodingType]cmds.Marshaller{ + cmds.Text: func(res cmds.Response) ([]byte, error) { + output := res.Output().(string) + return []byte(output), nil + }, }, - Type: &ResolveOutput{}, -} - -func resolve(n *core.IpfsNode, names []string) ([]IpnsEntry, error) { - var entries []IpnsEntry - for _, name := range names { - resolved, err := n.Namesys.Resolve(name) - if err != nil { - return nil, err - } - entries = append(entries, IpnsEntry{ - Name: name, - Value: resolved, - }) - } - return entries, nil }