Skip to content

Commit 3d1802f

Browse files
authored
Merge pull request #5345 from ipfs/fix/5335
return a json object from config show
2 parents 99df463 + 6d67f89 commit 3d1802f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

core/commands/config.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ var configShowCmd = &cmds.Command{
153153
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.
154154
`,
155155
},
156-
156+
Type: map[string]interface{}{},
157157
Run: func(req cmds.Request, res cmds.Response) {
158158
cfgPath := req.InvocContext().ConfigRoot
159159
fname, err := config.Filename(cfgPath)
@@ -180,14 +180,31 @@ NOTE: For security reasons, this command will omit your private key. If you woul
180180
res.SetError(err, cmdkit.ErrNormal)
181181
return
182182
}
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+
}
183190

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+
}
189200

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+
},
191208
},
192209
}
193210

0 commit comments

Comments
 (0)