@cryptotaxi247 / kubo / commits / 5af442da8

refact(cmd/init): change string option to const

License: MIT Signed-off-by: chenminjian <727180553@qq.com>

chenminjian committed Jan 27, 2019 at 14:46 UTC 5af442da8d0164655a8c36a1ca3c8794a16522b8
1 file changed +9 -6
cmd/ipfs/init.go
+9 -6
@@ -24,6 +24,9 @@ import (
24
25 const (
26 nBitsForKeypairDefault = 2048
27 + bitsOptionName = "bits"
28 + emptyRepoOptionName = "empty-repo"
29 + profileOptionName = "profile"
30 )
31
32 var initCmd = &cmds.Command{
@@ -48,9 +51,9 @@ environment variable:
51 cmdkit.FileArg("default-config", false, false, "Initialize with the given configuration.").EnableStdin(),
52 },
53 Options: []cmdkit.Option{
51 - cmdkit.IntOption("bits", "b", "Number of bits to use in the generated RSA private key.").WithDefault(nBitsForKeypairDefault),
52 - cmdkit.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage."),
53 - cmdkit.StringOption("profile", "p", "Apply profile settings to config. Multiple profiles can be separated by ','"),
54 + cmdkit.IntOption(bitsOptionName, "b", "Number of bits to use in the generated RSA private key.").WithDefault(nBitsForKeypairDefault),
55 + cmdkit.BoolOption(emptyRepoOptionName, "e", "Don't add and pin help files to the local storage."),
56 + cmdkit.StringOption(profileOptionName, "p", "Apply profile settings to config. Multiple profiles can be separated by ','"),
57
58 // TODO need to decide whether to expose the override as a file or a
59 // directory. That is: should we allow the user to also specify the
@@ -79,8 +82,8 @@ environment variable:
82 return cmdkit.Error{Message: "init must be run offline only"}
83 }
84
82 - empty, _ := req.Options["empty-repo"].(bool)
83 - nBitsForKeypair, _ := req.Options["bits"].(int)
85 + empty, _ := req.Options[emptyRepoOptionName].(bool)
86 + nBitsForKeypair, _ := req.Options[bitsOptionName].(int)
87
88 var conf *config.Config
89
@@ -104,7 +107,7 @@ environment variable:
107 }
108 }
109
107 - profile, _ := req.Options["profile"].(string)
110 + profile, _ := req.Options[profileOptionName].(string)
111
112 var profiles []string
113 if profile != "" {