Documentation
¶
Overview ¶
Package output provides structured output formatting for glean-cli commands.
Package output provides standardized output formatting with syntax highlighting for various data formats like JSON and YAML. It handles terminal detection and colorization based on the environment and user preferences.
Index ¶
- Constants
- func ProjectFields(w io.Writer, v any, fields string) error
- func Write(w io.Writer, content []byte, opts Options) error
- func WriteFormatted(w io.Writer, v any, outputFormat string, textFn func(io.Writer, any) error) error
- func WriteJSON(w io.Writer, v any) error
- func WriteNDJSON(w io.Writer, v any) error
- func WriteString(w io.Writer, content string, opts Options) error
- type Options
Constants ¶
const ( OutputJSON = "json" OutputNDJSON = "ndjson" OutputText = "text" )
Format constants for --output flag values.
const ( FormatJSON = "json" FormatYAML = "yaml" )
Format constants for supported output formats.
Variables ¶
This section is empty.
Functions ¶
func ProjectFields ¶
ProjectFields marshals v to JSON, then filters to only the specified dot-path fields. fields is a comma-separated list like "title,document.url,metadata.datasource". If fields is empty, the full value is written.
func Write ¶
Write formats and writes content to the writer with optional syntax highlighting. It supports JSON and YAML formats, automatically indenting and colorizing the output when appropriate for the terminal environment.
func WriteFormatted ¶
func WriteFormatted(w io.Writer, v any, outputFormat string, textFn func(io.Writer, any) error) error
WriteFormatted writes v in the format specified by outputFormat. textFn is called for OutputText; it should write human-readable output to w.
func WriteNDJSON ¶
WriteNDJSON marshals each element of a slice as a separate JSON line to w. For SearchResponse, it emits one result per line instead of the full envelope. If v is not a slice, it writes the whole value as a single line.