fix(app): pretty-print JSON on a terminal and reconcile the foundation streams

writeJSON uses the indented, colored JSON writer when stdout is a
terminal. Help and JSON tests now expect the -L shorthand column and
compare terminal JSON without color sequences.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 22:57:38 +02:00
1 parent 04d5f2aed0
commit 48a188ceac
4 files changed
+17 -8

No files matched your search

+2 -1
View File
@@ -55,7 +55,8 @@ func (a *application) writeHuman(cmd *cobra.Command, text string) error {
// writeJSON writes v as JSON, filtered by --json fields and --jq.
func (a *application) writeJSON(cmd *cobra.Command, v any) error {
return terminal.WriteJSON(cmd.OutOrStdout(), v, a.options.json, a.options.jq)
pretty := a.deps.Streams.OutTTY
return terminal.JSONOutput{Fields: a.options.json, Query: a.options.jq, Pretty: pretty, Color: pretty && a.colorEnabled()}.Write(cmd.OutOrStdout(), v)
}
// listSpec describes how a list command shows its items to people.