diff --git a/src/cli/print/print.go b/src/cli/print/print.go index d50315170..6d82f204c 100644 --- a/src/cli/print/print.go +++ b/src/cli/print/print.go @@ -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 // --------------------------------------------------------------------------------------------------------- diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index 9cc2fe927..a19aa50a2 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -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