refactor ipns command option name
License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com>
Kejie Zhang committed
Sep 17, 2018 at 15:09 UTC
e71ca7c5ad5a311440024f944197f51069b560a0
1 file changed
+15
-7
core/commands/name/ipns.go
+15
-7
@@ -25,6 +25,13 @@ type ResolvedPath struct {
25
Path path.Path
26
}
27
28
+const (
29
+ recursiveOptionName = "recursive"
30
+ nocacheOptionName = "nocache"
31
+ dhtRecordCountOptionName = "dht-record-count"
32
+ dhtTimeoutOptionName = "dht-timeout"
33
+)
34
+
35
var IpnsCmd = &cmds.Command{
36
Helptext: cmdkit.HelpText{
37
Tagline: "Resolve IPNS names.",
@@ -67,10 +74,10 @@ Resolve the value of a dnslink:
74
cmdkit.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID."),
75
},
76
Options: []cmdkit.Option{
70
- cmdkit.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name."),
71
- cmdkit.BoolOption("nocache", "n", "Do not use cached entries."),
72
- cmdkit.UintOption("dht-record-count", "dhtrc", "Number of records to request for DHT resolution."),
73
- cmdkit.StringOption("dht-timeout", "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
77
+ cmdkit.BoolOption(recursiveOptionName, "r", "Resolve until the result is not an IPNS name."),
78
+ cmdkit.BoolOption(nocacheOptionName, "n", "Do not use cached entries."),
79
+ cmdkit.UintOption(dhtRecordCountOptionName, "dhtrc", "Number of records to request for DHT resolution."),
80
+ cmdkit.StringOption(dhtTimeoutOptionName, "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
81
},
82
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
83
n, err := cmdenv.GetNode(env)
@@ -119,9 +126,10 @@ Resolve the value of a dnslink:
126
name = req.Arguments[0]
127
}
128
122
- recursive, _ := req.Options["recursive"].(bool)
123
- rc, rcok := req.Options["dht-record-count"].(int)
124
- dhtt, dhttok := req.Options["dht-timeout"].(string)
129
+ recursive, _ := req.Options[recursiveOptionName].(bool)
130
+ rc, rcok := req.Options[dhtRecordCountOptionName].(int)
131
+ dhtt, dhttok := req.Options[dhtTimeoutOptionName].(string)
132
+
133
var ropts []nsopts.ResolveOpt
134
if !recursive {
135
ropts = append(ropts, nsopts.Depth(1))