@cryptotaxi247 / kubo / commits / 68693783f

core/commands2: Made 'resolve' output match old command

Matt Bell committed Nov 9, 2014 at 21:06 UTC 68693783fef1fb1ec524bcdb93c12cf2b201a5f1
1 file changed +17 -33
core/commands2/resolve.go
+17 -33
@@ -4,13 +4,8 @@ import (
4 "errors"
5
6 cmds "github.com/jbenet/go-ipfs/commands"
7 - core "github.com/jbenet/go-ipfs/core"
7 )
8
10 -type ResolveOutput struct {
11 - Entries []IpnsEntry
12 -}
13 -
9 var resolveCmd = &cmds.Command{
10 Description: "Gets the value currently published at an IPNS name",
11 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:
28 `,
29
30 Arguments: []cmds.Argument{
36 - cmds.Argument{"name", cmds.ArgString, false, true,
31 + cmds.Argument{"name", cmds.ArgString, false, false,
32 "The IPNS name to resolve. Defaults to your node's peerID."},
33 },
34 Run: func(res cmds.Response, req cmds.Request) {
35
36 n := req.Context().Node
42 - var names []string
37 + var name string
38
39 if n.Network == nil {
40 res.SetError(errNotOnline, cmds.ErrNormal)
@@ -51,40 +46,29 @@ Resolve te value of another name:
46 res.SetError(errors.New("Identity not loaded!"), cmds.ErrNormal)
47 return
48 }
54 - names = append(names, n.Identity.ID().String())
49 + name = n.Identity.ID().String()
50 +
51 } else {
56 - for _, arg := range req.Arguments() {
57 - name, ok := arg.(string)
58 - if !ok {
59 - res.SetError(errors.New("cast error"), cmds.ErrNormal)
60 - return
61 - }
62 - names = append(names, name)
52 + var ok bool
53 + name, ok = req.Arguments()[0].(string)
54 + if !ok {
55 + res.SetError(errors.New("cast error"), cmds.ErrNormal)
56 + return
57 }
58 }
59
66 - entries, err := resolve(n, names)
60 + output, err := n.Namesys.Resolve(name)
61 if err != nil {
62 res.SetError(err, cmds.ErrNormal)
63 return
64 }
65
72 - res.SetOutput(&ResolveOutput{entries})
66 + res.SetOutput(output)
67 + },
68 + Marshallers: map[cmds.EncodingType]cmds.Marshaller{
69 + cmds.Text: func(res cmds.Response) ([]byte, error) {
70 + output := res.Output().(string)
71 + return []byte(output), nil
72 + },
73 },
74 - Type: &ResolveOutput{},
75 -}
76 -
77 -func resolve(n *core.IpfsNode, names []string) ([]IpnsEntry, error) {
78 - var entries []IpnsEntry
79 - for _, name := range names {
80 - resolved, err := n.Namesys.Resolve(name)
81 - if err != nil {
82 - return nil, err
83 - }
84 - entries = append(entries, IpnsEntry{
85 - Name: name,
86 - Value: resolved,
87 - })
88 - }
89 - return entries, nil
74 }