Commit c2ff0285 authored by W. Trevor King's avatar 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.
parent 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 is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment