mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 06:01:36 +03:00
f0aa65791b
* CHANGELOG text clarification * Dialing in config/options * Yet more dialing in of config/options * Refactor output writers * YAML output for more commands
30 lines
673 B
Go
30 lines
673 B
Go
// Package jsonw implements output writers for JSON.
|
|
package jsonw
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
"github.com/neilotoole/sq/cli/output/jsonw/internal"
|
|
jcolorenc "github.com/neilotoole/sq/cli/output/jsonw/internal/jcolorenc"
|
|
"github.com/neilotoole/sq/libsq/core/errz"
|
|
)
|
|
|
|
// writeJSON prints a JSON representation of v to out, using specs
|
|
// from pr.
|
|
func writeJSON(out io.Writer, pr *output.Printing, v any) error {
|
|
enc := jcolorenc.NewEncoder(out)
|
|
enc.SetColors(internal.NewColors(pr))
|
|
enc.SetEscapeHTML(false)
|
|
if pr.Pretty {
|
|
enc.SetIndent("", pr.Indent)
|
|
}
|
|
|
|
err := enc.Encode(v)
|
|
if err != nil {
|
|
return errz.Err(err)
|
|
}
|
|
|
|
return nil
|
|
}
|