mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:34:03 +08:00
core/commands2: Made 'resolve' output match old command
This commit is contained in:

committed by
Juan Batiz-Benet

parent
2d756473f6
commit
68693783fe
@ -4,13 +4,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
cmds "github.com/jbenet/go-ipfs/commands"
|
cmds "github.com/jbenet/go-ipfs/commands"
|
||||||
core "github.com/jbenet/go-ipfs/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResolveOutput struct {
|
|
||||||
Entries []IpnsEntry
|
|
||||||
}
|
|
||||||
|
|
||||||
var resolveCmd = &cmds.Command{
|
var resolveCmd = &cmds.Command{
|
||||||
Description: "Gets the value currently published at an IPNS name",
|
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
|
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{
|
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."},
|
"The IPNS name to resolve. Defaults to your node's peerID."},
|
||||||
},
|
},
|
||||||
Run: func(res cmds.Response, req cmds.Request) {
|
Run: func(res cmds.Response, req cmds.Request) {
|
||||||
|
|
||||||
n := req.Context().Node
|
n := req.Context().Node
|
||||||
var names []string
|
var name string
|
||||||
|
|
||||||
if n.Network == nil {
|
if n.Network == nil {
|
||||||
res.SetError(errNotOnline, cmds.ErrNormal)
|
res.SetError(errNotOnline, cmds.ErrNormal)
|
||||||
@ -51,40 +46,29 @@ Resolve te value of another name:
|
|||||||
res.SetError(errors.New("Identity not loaded!"), cmds.ErrNormal)
|
res.SetError(errors.New("Identity not loaded!"), cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
names = append(names, n.Identity.ID().String())
|
name = n.Identity.ID().String()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for _, arg := range req.Arguments() {
|
var ok bool
|
||||||
name, ok := arg.(string)
|
name, ok = req.Arguments()[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
res.SetError(errors.New("cast error"), cmds.ErrNormal)
|
res.SetError(errors.New("cast error"), cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
names = append(names, name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entries, err := resolve(n, names)
|
output, err := n.Namesys.Resolve(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
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
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user