@cryptotaxi247 / kubo / commits / c2ff02850

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.

W. Trevor King committed May 11, 2015 at 20:07 UTC c2ff02850b9a7064a23df6cea9cf6187a6d4155e
1 file changed +11 -1
core/commands/resolve.go
+11 -1
@@ -6,6 +6,7 @@ import (
6 "strings"
7
8 cmds "github.com/ipfs/go-ipfs/commands"
9 + namesys "github.com/ipfs/go-ipfs/namesys"
10 path "github.com/ipfs/go-ipfs/path"
11 u "github.com/ipfs/go-ipfs/util"
12 )
@@ -46,6 +47,9 @@ Resolve te value of another name:
47 Arguments: []cmds.Argument{
48 cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID.").EnableStdin(),
49 },
50 + Options: []cmds.Option{
51 + cmds.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name"),
52 + },
53 Run: func(req cmds.Request, res cmds.Response) {
54
55 n, err := req.Context().GetNode()
@@ -75,7 +79,13 @@ Resolve te value of another name:
79 name = req.Arguments()[0]
80 }
81
78 - output, err := n.Namesys.Resolve(n.Context(), "/ipns/"+name)
82 + recursive, _, _ := req.Option("recursive").Bool()
83 + depth := 1
84 + if recursive {
85 + depth = namesys.DefaultDepthLimit
86 + }
87 +
88 + output, err := n.Namesys.ResolveN(n.Context(), "/ipns/"+name, depth)
89 if err != nil {
90 res.SetError(err, cmds.ErrNormal)
91 return