don't split json output by type (#725)

## Description

Prevents output printing of detail entries from splitting into
multiple json arrays when the entries contains multiple item
type.s

## Type of change

Please check the type of change your PR introduces:
- [x] 🐛 Bugfix

## Issue(s)

#501 

## Test Plan

- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Keepers 2022-09-01 16:06:35 -06:00 committed by GitHub
parent da6288cb8b
commit 784f006da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -46,6 +46,11 @@ func AddOutputFlag(parent *cobra.Command) {
cobra.CheckErr(fs.MarkHidden("json-debug"))
}
// JSONFormat returns true if the printer plans to output as json.
func JSONFormat() bool {
return outputAsJSON || outputAsJSONDebug
}
// ---------------------------------------------------------------------------------------------------------
// Helper funcs
// ---------------------------------------------------------------------------------------------------------

View File

@ -24,6 +24,14 @@ type DetailsModel struct {
// Print writes the DetailModel Entries to StdOut, in the format
// requested by the caller.
func (dm DetailsModel) PrintEntries(ctx context.Context) {
if print.JSONFormat() {
printJSON(ctx, dm)
} else {
printTable(ctx, dm)
}
}
func printTable(ctx context.Context, dm DetailsModel) {
perType := map[itemType][]print.Printable{}
for _, de := range dm.Entries {
@ -42,6 +50,16 @@ func (dm DetailsModel) PrintEntries(ctx context.Context) {
}
}
func printJSON(ctx context.Context, dm DetailsModel) {
ents := []print.Printable{}
for _, ent := range dm.Entries {
ents = append(ents, print.Printable(ent))
}
print.All(ctx, ents...)
}
// Paths returns the list of Paths extracted from the Entries slice.
func (dm DetailsModel) Paths() []string {
ents := dm.Entries