Add --empty-repo option for init (#1559)
License: MIT Signed-off-by: Pavol Rusnak <stick@gk2.sk>
Pavol Rusnak committed
Aug 20, 2015 at 00:53 UTC
73e820a8bcbceb01ee6d97e5368b208d57a2222f
1 file changed
+14
-5
cmd/ipfs/init.go
+14
-5
@@ -27,6 +27,7 @@ var initCmd = &cmds.Command{
27
Options: []cmds.Option{
28
cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)),
29
cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
30
+ cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage"),
31
32
// TODO need to decide whether to expose the override as a file or a
33
// directory. That is: should we allow the user to also specify the
@@ -59,6 +60,12 @@ var initCmd = &cmds.Command{
60
return
61
}
62
63
+ empty, _, err := req.Option("e").Bool() // if !empty, it's okay empty == false
64
+ if err != nil {
65
+ res.SetError(err, cmds.ErrNormal)
66
+ return
67
+ }
68
+
69
nBitsForKeypair, bitsOptFound, err := req.Option("b").Int()
70
if err != nil {
71
res.SetError(err, cmds.ErrNormal)
@@ -69,7 +76,7 @@ var initCmd = &cmds.Command{
76
nBitsForKeypair = nBitsForKeypairDefault
77
}
78
72
- if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, nBitsForKeypair); err != nil {
79
+ if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, empty, nBitsForKeypair); err != nil {
80
res.SetError(err, cmds.ErrNormal)
81
return
82
}
@@ -82,10 +89,10 @@ Reinitializing would overwrite your keys.
89
`)
90
91
func initWithDefaults(out io.Writer, repoRoot string) error {
85
- return doInit(out, repoRoot, false, nBitsForKeypairDefault)
92
+ return doInit(out, repoRoot, false, false, nBitsForKeypairDefault)
93
}
94
88
-func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) error {
95
+func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeypair int) error {
96
if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
97
return err
98
}
@@ -113,8 +120,10 @@ func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) err
120
return err
121
}
122
116
- if err := addDefaultAssets(out, repoRoot); err != nil {
117
- return err
123
+ if !empty {
124
+ if err := addDefaultAssets(out, repoRoot); err != nil {
125
+ return err
126
+ }
127
}
128
129
return initializeIpnsKeyspace(repoRoot)