提交 c2ff0285 作者: W. Trevor King

core/commands/resolve: Add a -r / --recursive option

For explicitly enabling recursive behaviour (it was previously always
enabled).  That allows folks who are interested in understanding
layered indirection to step through the chain one link at a time.
上级 3ead2443
......@@ -6,6 +6,7 @@ import (
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
namesys "github.com/ipfs/go-ipfs/namesys"
path "github.com/ipfs/go-ipfs/path"
u "github.com/ipfs/go-ipfs/util"
)
......@@ -46,6 +47,9 @@ Resolve te value of another name:
Arguments: []cmds.Argument{
cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.Context().GetNode()
......@@ -75,7 +79,13 @@ Resolve te value of another name:
name = req.Arguments()[0]
}
output, err := n.Namesys.Resolve(n.Context(), "/ipns/"+name)
recursive, _, _ := req.Option("recursive").Bool()
depth := 1
if recursive {
depth = namesys.DefaultDepthLimit
}
output, err := n.Namesys.ResolveN(n.Context(), "/ipns/"+name, depth)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论