Documentation
¶
Overview ¶
Package output provides shared output writing and failure classification.
Index ¶
- Constants
- Variables
- func ApplyJSONPath(value gjson.Result, path string) gjson.Result
- func CountTerminalLines(data []byte, terminalWidth int) int
- func CreatePrivateDownloadFile(root *os.Root, name string) (*os.File, error)
- func FormatJSON(res gjson.Result, opts FormatOptions, destination io.Writer, terminal bool) ([]byte, error)
- func IsBrokenPipe(err error) bool
- func ResolveFormat(opts FormatOptions) string
- func Stream(label string, generateOutput func(w *os.File) error) error
- func StreamToPager(label string, generateOutput func(w *os.File) error) error
- func StreamToPagerWithPipe(label string, generateOutput func(w *os.File) error) error
- func StreamToStdout(generateOutput func(w *os.File) error) error
- func Transform(ctx context.Context, value gjson.Result, transform transformers.Transformer) (gjson.Result, error)
- func UseColors(terminal bool) bool
- func WriteFiniteJSONList[T any](source jsonview.Iterator[T], opts FiniteJSONListOptions) error
- func WriteReadableIterator(iter jsonview.Iterator[JSON], opts ReadableOptions) error
- func WriteReadableResource(out io.Writer, value gjson.Result, opts ReadableOptions) (bool, error)
- type DiagnosticError
- type FiniteJSONListError
- type FiniteJSONListOptions
- type FormatOptions
- type Iterator
- type IteratorOptions
- type JSON
- type PagerError
- type ReadableOptions
- type StreamResultError
- type WriteError
- type Writer
Constants ¶
const ResourceSummaryHint = "Full data: --format json."
Variables ¶
var Formats = []string{"auto", "text", "explore", "json", "jsonl", "pretty", "raw", "yaml"}
Functions ¶
func ApplyJSONPath ¶
ApplyJSONPath preserves the original value when the requested path is absent.
func CountTerminalLines ¶
CountTerminalLines counts wrapped newlines using the existing pager policy.
func CreatePrivateDownloadFile ¶
CreatePrivateDownloadFile exclusively creates private download staging inside root.
func FormatJSON ¶
func FormatJSON(res gjson.Result, opts FormatOptions, destination io.Writer, terminal bool) ([]byte, error)
FormatJSON formats one result. The caller classifies the final destination, including feature wrappers and terminals behind pagers; intermediate buffers must not change terminal escaping or color policy.
func IsBrokenPipe ¶
IsBrokenPipe reports whether every cause is a broken output pipe, excluding diagnostic writes and upstream failures.
func ResolveFormat ¶
func ResolveFormat(opts FormatOptions) string
Automatic output is readable on every destination. Extraction keeps its existing JSON/raw-string contract, including when stdout is redirected.
func StreamToPagerWithPipe ¶
StreamToPagerWithPipe runs the pipe-based pager transport used on Windows and when the Unix socket transport cannot be established.
func StreamToStdout ¶
StreamToStdout preserves stdout signal handling and suppresses only failures classified as broken output pipes, retaining upstream and diagnostic errors.
func Transform ¶
func Transform(ctx context.Context, value gjson.Result, transform transformers.Transformer) (gjson.Result, error)
Transform checks cancellation before and after one response transformation.
func WriteFiniteJSONList ¶
func WriteFiniteJSONList[T any](source jsonview.Iterator[T], opts FiniteJSONListOptions) error
WriteFiniteJSONList frames a finite source as one JSON array without collecting the complete result. The caller retains ownership of the source.
func WriteReadableIterator ¶
func WriteReadableIterator(iter jsonview.Iterator[JSON], opts ReadableOptions) error
WriteReadableIterator renders records as they arrive, keeping stream state separate from list records.
func WriteReadableResource ¶
WriteReadableResource applies resource projections to readable results without field extraction. Report omissions so each response or list can explain them once.
Types ¶
type DiagnosticError ¶
type DiagnosticError struct{ Err error }
DiagnosticError identifies failures that belong to stderr, even inside stdout's stream lifecycle.
func (*DiagnosticError) Error ¶
func (e *DiagnosticError) Error() string
func (*DiagnosticError) Unwrap ¶
func (e *DiagnosticError) Unwrap() error
type FiniteJSONListError ¶
type FiniteJSONListError struct{}
FiniteJSONListError contains a fixed diagnostic for malformed list items. It never includes response data or parser error details.
func (*FiniteJSONListError) Error ¶
func (*FiniteJSONListError) Error() string
type FiniteJSONListOptions ¶
type FiniteJSONListOptions struct {
IteratorOptions
Stdout io.Writer
Terminal bool
Title string
}
FiniteJSONListOptions carries an already selected finite-list presentation. Callers supply Context and Transform, check initial source/cancellation errors, and apply feature selection before invoking WriteFiniteJSONList. Terminal describes the final destination, including wrapped terminal writers.
type FormatOptions ¶
FormatOptions describes one JSON value after feature-specific transformation. Interactive exploration, paging, and output lifecycle remain with the caller.
type Iterator ¶
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator shares one lazy transformation boundary across direct output, the pager, and the explorer. Current never reruns a transformation.
func NewIterator ¶
func NewIterator[T any](source jsonview.Iterator[T], opts IteratorOptions) *Iterator[T]
NewIterator shares one lazy transformation boundary between output consumers. Construction does not advance the source or inspect its error state.
type IteratorOptions ¶
type IteratorOptions struct {
Context context.Context
Transform transformers.Transformer
Route transformers.Route
Limit int64
}
IteratorOptions retains the caller's route, transformation, and item boundary. Zero Limit consumes no items; negative Limit is unlimited. Callers supply a Context and Transform for any iterator they advance.
type PagerError ¶
type PagerError struct {
// contains filtered or unexported fields
}
PagerError distinguishes pager setup and process failures from the request, formatter, or output callback. Keep the cause available to errors.Is/As.
func (*PagerError) Unwrap ¶
func (e *PagerError) Unwrap() error
type ReadableOptions ¶
type ReadableOptions struct {
Context context.Context
Route transformers.Route
FormatOptions
Stdout, Stderr io.Writer
Terminal bool
DiagnosticsAllowed bool
}
ReadableOptions describes an already selected readable presentation. Assembly supplies a non-nil Context and writers, the final destination classification, and permission to emit optional diagnostics. The iterator is already transformed.
type StreamResultError ¶
type StreamResultError struct{ Message string }
StreamResultError carries only fixed classifications from the stream transformers, never API prose, so the command presenter can retain meaning.
func (*StreamResultError) Error ¶
func (e *StreamResultError) Error() string
type WriteError ¶
type WriteError struct{ Err error }
WriteError identifies failures from the output sink, rather than from the iterator, transport, or formatter producing the output.
func (*WriteError) Error ¶
func (e *WriteError) Error() string
func (*WriteError) Unwrap ¶
func (e *WriteError) Unwrap() error