mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-31 15:31:09 +08:00
refactor all command code
License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com>
This commit is contained in:
@ -20,6 +20,12 @@ import (
|
||||
"gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
|
||||
)
|
||||
|
||||
const (
|
||||
resolveRecursiveOptionName = "recursive"
|
||||
resolveDhtRecordCountOptionName = "dht-record-count"
|
||||
resolveDhtTimeoutOptionName = "dht-timeout"
|
||||
)
|
||||
|
||||
var ResolveCmd = &cmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Resolve the value of names to IPFS.",
|
||||
@ -64,9 +70,9 @@ Resolve the value of an IPFS DAG path:
|
||||
cmdkit.StringArg("name", true, false, "The name to resolve.").EnableStdin(),
|
||||
},
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption("recursive", "r", "Resolve until the result is an IPFS name."),
|
||||
cmdkit.IntOption("dht-record-count", "dhtrc", "Number of records to request for DHT resolution."),
|
||||
cmdkit.StringOption("dht-timeout", "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
|
||||
cmdkit.BoolOption(resolveRecursiveOptionName, "r", "Resolve until the result is an IPFS name."),
|
||||
cmdkit.IntOption(resolveDhtRecordCountOptionName, "dhtrc", "Number of records to request for DHT resolution."),
|
||||
cmdkit.StringOption(resolveDhtTimeoutOptionName, "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env)
|
||||
@ -87,12 +93,12 @@ Resolve the value of an IPFS DAG path:
|
||||
}
|
||||
|
||||
name := req.Arguments[0]
|
||||
recursive, _ := req.Options["recursive"].(bool)
|
||||
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
|
||||
|
||||
// the case when ipns is resolved step by step
|
||||
if strings.HasPrefix(name, "/ipns/") && !recursive {
|
||||
rc, rcok := req.Options["dht-record-count"].(uint)
|
||||
dhtt, dhttok := req.Options["dht-timeout"].(string)
|
||||
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
|
||||
dhtt, dhttok := req.Options[resolveDhtTimeoutOptionName].(string)
|
||||
ropts := []options.NameResolveOption{
|
||||
options.Name.ResolveOption(nsopts.Depth(1)),
|
||||
}
|
||||
|
Reference in New Issue
Block a user