From c2ff02850b9a7064a23df6cea9cf6187a6d4155e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 11 May 2015 20:07:13 -0700 Subject: [PATCH] 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. --- core/commands/resolve.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/commands/resolve.go b/core/commands/resolve.go index 2d9b5906e..ff7b5df5b 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -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