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:
parent
da6288cb8b
commit
784f006da5
@ -46,6 +46,11 @@ func AddOutputFlag(parent *cobra.Command) {
|
|||||||
cobra.CheckErr(fs.MarkHidden("json-debug"))
|
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
|
// Helper funcs
|
||||||
// ---------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -24,6 +24,14 @@ type DetailsModel struct {
|
|||||||
// Print writes the DetailModel Entries to StdOut, in the format
|
// Print writes the DetailModel Entries to StdOut, in the format
|
||||||
// requested by the caller.
|
// requested by the caller.
|
||||||
func (dm DetailsModel) PrintEntries(ctx context.Context) {
|
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{}
|
perType := map[itemType][]print.Printable{}
|
||||||
|
|
||||||
for _, de := range dm.Entries {
|
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.
|
// Paths returns the list of Paths extracted from the Entries slice.
|
||||||
func (dm DetailsModel) Paths() []string {
|
func (dm DetailsModel) Paths() []string {
|
||||||
ents := dm.Entries
|
ents := dm.Entries
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user