@cryptotaxi247 / kubo / commits / 6d67f8923

return a json object from config show

This doesn't change there CLI output, it just means that the server responds with a JSON output by default. fixes #5335 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Aug 6, 2018 at 13:30 UTC 6d67f892328db205a0feec5441b7b5bf221e80bb
1 file changed +24 -7
core/commands/config.go
+24 -7
@@ -153,7 +153,7 @@ var configShowCmd = &cmds.Command{
153 NOTE: For security reasons, this command will omit your private key. If you would like to make a full backup of your config (private key included), you must copy the config file from your repo.
154 `,
155 },
156 -
156 + Type: map[string]interface{}{},
157 Run: func(req cmds.Request, res cmds.Response) {
158 cfgPath := req.InvocContext().ConfigRoot
159 fname, err := config.Filename(cfgPath)
@@ -180,14 +180,31 @@ NOTE: For security reasons, this command will omit your private key. If you woul
180 res.SetError(err, cmdkit.ErrNormal)
181 return
182 }
183 + res.SetOutput(&cfg)
184 + },
185 + Marshalers: cmds.MarshalerMap{
186 + cmds.Text: func(res cmds.Response) (io.Reader, error) {
187 + if res.Error() != nil {
188 + return nil, res.Error()
189 + }
190
184 - output, err := config.HumanOutput(cfg)
185 - if err != nil {
186 - res.SetError(err, cmdkit.ErrNormal)
187 - return
188 - }
191 + v, err := unwrapOutput(res.Output())
192 + if err != nil {
193 + return nil, err
194 + }
195 +
196 + cfg, ok := v.(*map[string]interface{})
197 + if !ok {
198 + return nil, e.TypeErr(cfg, v)
199 + }
200
190 - res.SetOutput(bytes.NewReader(output))
201 + buf, err := config.HumanOutput(cfg)
202 + if err != nil {
203 + return nil, err
204 + }
205 + buf = append(buf, byte('\n'))
206 + return bytes.NewReader(buf), nil
207 + },
208 },
209 }
210