Skip to content

Commit f2f677b

Browse files
authored
Merge pull request #5949 from chenminjian/refact/cmd/init
refact(cmd/init): change string option to const
2 parents f0a26c1 + 5af442d commit f2f677b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

cmd/ipfs/init.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424

2525
const (
2626
nBitsForKeypairDefault = 2048
27+
bitsOptionName = "bits"
28+
emptyRepoOptionName = "empty-repo"
29+
profileOptionName = "profile"
2730
)
2831

2932
var initCmd = &cmds.Command{
@@ -48,9 +51,9 @@ environment variable:
4851
cmdkit.FileArg("default-config", false, false, "Initialize with the given configuration.").EnableStdin(),
4952
},
5053
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 ','"),
5457

5558
// TODO need to decide whether to expose the override as a file or a
5659
// directory. That is: should we allow the user to also specify the
@@ -79,8 +82,8 @@ environment variable:
7982
return cmdkit.Error{Message: "init must be run offline only"}
8083
}
8184

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)
8487

8588
var conf *config.Config
8689

@@ -104,7 +107,7 @@ environment variable:
104107
}
105108
}
106109

107-
profile, _ := req.Options["profile"].(string)
110+
profile, _ := req.Options[profileOptionName].(string)
108111

109112
var profiles []string
110113
if profile != "" {

0 commit comments

Comments
 (0)