cleaned up 'ipfs init'
Henry committed
Mar 8, 2015 at 02:38 UTC
70819671d3071a011bdc06bd929e37e6a6741161
1 file changed
+16
-9
cmd/ipfs/init.go
+16
-9
@@ -28,7 +28,6 @@ var initCmd = &cmds.Command{
28
29
Options: []cmds.Option{
30
cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key (defaults to 4096)"),
31
- cmds.StringOption("passphrase", "p", "Passphrase for encrypting the private key"),
31
cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
32
33
// TODO need to decide whether to expose the override as a file or a
@@ -49,6 +48,7 @@ var initCmd = &cmds.Command{
48
res.SetError(err, cmds.ErrNormal)
49
return
50
}
51
+
52
if !bitsOptFound {
53
nBitsForKeypair = nBitsForKeypairDefault
54
}
@@ -75,28 +75,26 @@ func initWithDefaults(out io.Writer, repoRoot string) error {
75
return debugerror.Wrap(err)
76
}
77
78
-func writef(out io.Writer, format string, ifs ...interface{}) error {
79
- _, err := out.Write([]byte(fmt.Sprintf(format, ifs...)))
80
- return err
81
-}
82
-
78
func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) error {
84
- if err := writef(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
79
+ if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
80
return err
81
}
82
83
if fsrepo.IsInitialized(repoRoot) && !force {
84
return errRepoExists
85
}
86
+
87
conf, err := config.Init(out, nBitsForKeypair)
88
if err != nil {
89
return err
90
}
91
+
92
if fsrepo.IsInitialized(repoRoot) {
93
if err := fsrepo.Remove(repoRoot); err != nil {
94
return err
95
}
96
}
97
+
98
if err := fsrepo.Init(repoRoot, conf); err != nil {
99
return err
100
}
@@ -111,10 +109,12 @@ func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) err
109
func addDefaultAssets(out io.Writer, repoRoot string) error {
110
ctx, cancel := context.WithCancel(context.Background())
111
defer cancel()
112
+
113
r := fsrepo.At(repoRoot)
114
if err := r.Open(); err != nil { // NB: repo is owned by the node
115
return err
116
}
117
+
118
nd, err := core.NewIPFSNode(ctx, core.Offline(r))
119
if err != nil {
120
return err
@@ -130,6 +130,7 @@ func addDefaultAssets(out io.Writer, repoRoot string) error {
130
if err != nil {
131
return err
132
}
133
+
134
k := u.B58KeyDecode(s)
135
if err := dirb.AddChild(fname, k); err != nil {
136
return err
@@ -141,15 +142,21 @@ func addDefaultAssets(out io.Writer, repoRoot string) error {
142
if err != nil {
143
return err
144
}
145
+
146
if err := nd.Pinning.Pin(dir, true); err != nil {
147
return err
148
}
149
+
150
if err := nd.Pinning.Flush(); err != nil {
151
return err
152
}
153
151
- writef(out, "to get started, enter:\n")
152
- return writef(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
154
+ if _, err = fmt.Fprintf(out, "to get started, enter:\n"); err != nil {
155
+ return err
156
+ }
157
+
158
+ _, err = fmt.Fprintf(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
159
+ return err
160
}
161
162
func initializeIpnsKeyspace(repoRoot string) error {