output

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const (
	OutputJSON   = "json"
	OutputNDJSON = "ndjson"
	OutputText   = "text"
)

Format constants for --output flag values.

View Source
const (
	FormatJSON = "json"
	FormatYAML = "yaml"
)

Format constants for supported output formats.

Variables

This section is empty.

Functions

func ProjectFields

func ProjectFields(w io.Writer, v any, fields string) error

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

func Write(w io.Writer, content []byte, opts Options) error

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 WriteJSON

func WriteJSON(w io.Writer, v any) error

WriteJSON marshals v as indented JSON to w.

func WriteNDJSON

func WriteNDJSON(w io.Writer, v any) error

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.

func WriteString

func WriteString(w io.Writer, content string, opts Options) error

WriteString is a convenience wrapper for Write that accepts a string input. It converts the string to bytes and delegates to Write for formatting and output.

Types

type Options

type Options struct {
	// Format specifies the output format (json or yaml)
	Format string
	// NoColor disables syntax highlighting even in terminal environments
	NoColor bool
}

Options configures the output formatting behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL