cmds: use w.Write directly
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
Overbool committed
Nov 6, 2018 at 10:18 UTC
0afbafdeaf42fa6aa6140905a3149ce6db9969d8
2 files changed
+43
-20
core/commands/config.go
+39
-16
@@ -10,14 +10,14 @@ import (
10
"os/exec"
11
"strings"
12
13
- oldcmds "github.com/ipfs/go-ipfs/commands"
13
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
14
repo "github.com/ipfs/go-ipfs/repo"
15
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
16
17
"gx/ipfs/QmP2i47tnU23ijdshrZtuvrSkQPtf9HhsMb9fwGVe8owj2/jsondiff"
18
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
19
config "gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
20
- "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
20
+ cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
21
)
22
23
// ConfigUpdateOutput is config profile apply command's output
@@ -86,8 +86,11 @@ Set the value of the 'Datastore.Path' key:
86
default:
87
}
88
89
- ctx := env.(*oldcmds.Context)
90
- r, err := fsrepo.Open(ctx.ConfigRoot)
89
+ cfgRoot, err := cmdenv.GetConfigRoot(env)
90
+ if err != nil {
91
+ return err
92
+ }
93
+ r, err := fsrepo.Open(cfgRoot)
94
if err != nil {
95
return err
96
}
@@ -128,7 +131,9 @@ Set the value of the 'Datastore.Path' key:
131
if err != nil {
132
return err
133
}
131
- fmt.Fprintln(w, string(buf))
134
+ buf = append(buf, byte('\n'))
135
+
136
+ w.Write(buf)
137
return nil
138
}),
139
},
@@ -144,9 +149,12 @@ NOTE: For security reasons, this command will omit your private key. If you woul
149
},
150
Type: map[string]interface{}{},
151
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
147
- ctx := env.(*oldcmds.Context)
148
- cfgPath := ctx.ConfigRoot
149
- fname, err := config.Filename(cfgPath)
152
+ cfgRoot, err := cmdenv.GetConfigRoot(env)
153
+ if err != nil {
154
+ return err
155
+ }
156
+
157
+ fname, err := config.Filename(cfgRoot)
158
if err != nil {
159
return err
160
}
@@ -175,7 +183,9 @@ NOTE: For security reasons, this command will omit your private key. If you woul
183
if err != nil {
184
return err
185
}
178
- fmt.Fprintln(w, string(buf))
186
+ buf = append(buf, byte('\n'))
187
+ w.Write(buf)
188
+
189
return nil
190
}),
191
},
@@ -232,8 +242,12 @@ variable set to your preferred text editor.
242
},
243
244
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
235
- ctx := env.(*oldcmds.Context)
236
- filename, err := config.Filename(ctx.ConfigRoot)
245
+ cfgRoot, err := cmdenv.GetConfigRoot(env)
246
+ if err != nil {
247
+ return err
248
+ }
249
+
250
+ filename, err := config.Filename(cfgRoot)
251
if err != nil {
252
return err
253
}
@@ -255,8 +269,12 @@ can't be undone.
269
cmdkit.FileArg("file", true, false, "The file to use as the new config."),
270
},
271
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
258
- ctx := env.(*oldcmds.Context)
259
- r, err := fsrepo.Open(ctx.ConfigRoot)
272
+ cfgRoot, err := cmdenv.GetConfigRoot(env)
273
+ if err != nil {
274
+ return err
275
+ }
276
+
277
+ r, err := fsrepo.Open(cfgRoot)
278
if err != nil {
279
return err
280
}
@@ -303,8 +321,12 @@ var configProfileApplyCmd = &cmds.Command{
321
}
322
323
dryRun, _ := req.Options["dry-run"].(bool)
306
- ctx := env.(*oldcmds.Context)
307
- oldCfg, newCfg, err := transformConfig(ctx.ConfigRoot, req.Arguments[0], profile.Transform, dryRun)
324
+ cfgRoot, err := cmdenv.GetConfigRoot(env)
325
+ if err != nil {
326
+ return err
327
+ }
328
+
329
+ oldCfg, newCfg, err := transformConfig(cfgRoot, req.Arguments[0], profile.Transform, dryRun)
330
if err != nil {
331
return err
332
}
@@ -329,7 +351,8 @@ var configProfileApplyCmd = &cmds.Command{
351
diff := jsondiff.Compare(out.OldCfg, out.NewCfg)
352
buf := jsondiff.Format(diff)
353
332
- fmt.Fprint(w, string(buf))
354
+ w.Write(buf)
355
+
356
return nil
357
}),
358
},
core/commands/mount_unix.go
+4
-4
@@ -93,7 +93,7 @@ baz
93
94
// error if we aren't running node in online mode
95
if nd.LocalMode() {
96
- return err
96
+ return ErrNotOnline
97
}
98
99
fsdir, found := req.Options[mountIPFSPathOptionName].(string)
@@ -120,9 +120,9 @@ baz
120
Type: config.Mounts{},
121
Encoders: cmds.EncoderMap{
122
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, mounts *config.Mounts) error {
123
- s := fmt.Sprintf("IPFS mounted at: %s\n", mounts.IPFS)
124
- s += fmt.Sprintf("IPNS mounted at: %s\n", mounts.IPNS)
125
- fmt.Fprint(w, s)
123
+ fmt.Fprintf(w, "IPFS mounted at: %s\n", mounts.IPFS)
124
+ fmt.Fprintf(w, "IPNS mounted at: %s\n", mounts.IPNS)
125
+
126
return nil
127
}),
128
},