Added Default logic to `ipfs init`
Related to #2484 License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
Richard Littauer committed
May 10, 2016 at 16:42 UTC
d3cbf0eeb942fc928e6e609d114636a99c99ea72
1 file changed
+7
-9
cmd/ipfs/init.go
+7
-9
@@ -17,7 +17,9 @@ import (
17
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
18
)
19
20
-const nBitsForKeypairDefault = 2048
20
+const (
21
+ nBitsForKeypairDefault = 2048
22
+)
23
24
var initCmd = &cmds.Command{
25
Helptext: cmds.HelpText{
@@ -35,8 +37,8 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
37
cmds.FileArg("default-config", false, false, "Initialize with the given configuration.").EnableStdin(),
38
},
39
Options: []cmds.Option{
38
- cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)),
39
- cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage."),
40
+ cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key.").Default(nBitsForKeypairDefault),
41
+ cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage.").Default(false),
42
43
// TODO need to decide whether to expose the override as a file or a
44
// directory. That is: should we allow the user to also specify the
@@ -64,22 +66,18 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable
66
return
67
}
68
67
- empty, _, err := req.Option("e").Bool() // if !empty, it's okay empty == false
69
+ empty, _, err := req.Option("e").Bool()
70
if err != nil {
71
res.SetError(err, cmds.ErrNormal)
72
return
73
}
74
73
- nBitsForKeypair, bitsOptFound, err := req.Option("b").Int()
75
+ nBitsForKeypair, _, err := req.Option("b").Int()
76
if err != nil {
77
res.SetError(err, cmds.ErrNormal)
78
return
79
}
80
79
- if !bitsOptFound {
80
- nBitsForKeypair = nBitsForKeypairDefault
81
- }
82
-
81
var conf *config.Config
82
83
f := req.Files()