Skip to content

Commit

Permalink
return a json object from config show
Browse files Browse the repository at this point in the history
This doesn't change there CLI output, it just means that the server responds
with a JSON output by default.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Aug 6, 2018
1 parent d0a1cee commit 2f48b9a
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions core/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var configShowCmd = &cmds.Command{
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.
`,
},

Type: map[string]interface{}{},
Run: func(req cmds.Request, res cmds.Response) {
cfgPath := req.InvocContext().ConfigRoot
fname, err := config.Filename(cfgPath)
Expand All @@ -180,14 +180,31 @@ NOTE: For security reasons, this command will omit your private key. If you woul
res.SetError(err, cmdkit.ErrNormal)
return
}
res.SetOutput(&cfg)
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
if res.Error() != nil {
return nil, res.Error()
}

output, err := config.HumanOutput(cfg)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
v, err := unwrapOutput(res.Output())
if err != nil {
return nil, err
}

cfg, ok := v.(*map[string]interface{})
if !ok {
return nil, e.TypeErr(cfg, v)
}

res.SetOutput(bytes.NewReader(output))
buf, err := config.HumanOutput(cfg)
if err != nil {
return nil, err
}
buf = append(buf, byte('\n'))
return bytes.NewReader(buf), nil
},
},
}

Expand Down

0 comments on commit 2f48b9a

Please sign in to comment.