output

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const EmptyTableMessage = "(no results)"

EmptyTableMessage is what PrintTable writes when it has no rows.

Variables

This section is empty.

Functions

func ConstrainFlag added in v0.0.3

func ConstrainFlag(flag *pflag.Flag, def string, allowed ...string)

ConstrainFlag applies a default and enum validation to an existing string flag. Flags already created by NewEnumFlag or NewFormatFlag retain their command-specific default and allowed values.

func Fprint

func Fprint(w io.Writer, format Format, data any) error

Fprint formats and writes data to w in the given format.

func FprintJSONSemantics added in v0.0.3

func FprintJSONSemantics(w io.Writer, format Format, data any) error

FprintJSONSemantics formats JSON-backed data without letting YAML reflection change its field names or scalar types. It is opt-in for callers whose data model is defined by JSON tags and json.Marshaler implementations, such as the Console API. Generic Fprint keeps its existing YAML-tag behavior.

func NewEnumFlag added in v0.0.3

func NewEnumFlag(def string, allowed ...string) pflag.Value

NewEnumFlag returns a string flag value restricted to allowed.

func NewFormatFlag added in v0.0.3

func NewFormatFlag(def string, additional ...string) pflag.Value

NewFormatFlag returns the value to register --output with, seeded with the default format. Additional values are command-specific extensions, such as jsonl on workflow commands.

func PrintData

func PrintData(cmd *cobra.Command, columns []Column, rows [][]string, data any) error

PrintData is the unified output function for list commands. For table format, it prints columns and rows as an aligned table. For JSON/YAML, it serializes the structured data.

func PrintStreamRecord added in v0.0.3

func PrintStreamRecord(cmd *cobra.Command, structured any, pretty string) error

PrintStreamRecord writes one record in the selected stream format. JSON is one compact object per line, YAML is one document per record, and the caller supplies the human-readable pretty line.

func PrintTable

func PrintTable(w io.Writer, columns []Column, rows [][]string) error

PrintTable writes rows as an aligned table.

With no rows it writes EmptyTableMessage instead of a header on its own: a lone header reads as a rendering failure rather than as an empty result (SPEC §10.3). Callers that can name what is missing should say so themselves and skip this call. This is the legacy tabwriter engine, kept for the remaining PrintData callers; pretty output uses pretty.WriteTableOrEmpty (SPEC §10.12).

func RunShellOutput added in v0.0.3

func RunShellOutput(cmd *cobra.Command, interactive, tty bool, run ShellRunner) error

RunShellOutput preserves the interactive byte stream in pretty mode and turns an explicit remote command into one structured result in JSON/YAML mode. Structured output cannot represent an interactive terminal session, so it is rejected before the runner opens a provider connection.

func TerminalAwareWriter added in v0.0.3

func TerminalAwareWriter(w io.Writer) io.Writer

TerminalAwareWriter preserves styling on an interactive terminal and strips it from redirected output, in-memory writers, and explicit no-color sessions.

func ValidateShellOutput added in v0.0.3

func ValidateShellOutput(cmd *cobra.Command, interactive bool) error

ValidateShellOutput rejects the interactive mode that structured output cannot represent. Callers use this before resolving a provider connection; RunShellOutput repeats it to keep the shared boundary safe in isolation.

Types

type CheckedWriter added in v0.1.0

type CheckedWriter struct {
	// contains filtered or unexported fields
}

CheckedWriter retains the first destination failure and turns a nil-error prefix write into io.ErrShortWrite. It lets void render helpers keep their signatures without allowing them to report a successful command after stdout failed.

func NewCheckedTerminalWriter added in v1.0.1

func NewCheckedTerminalWriter(destination io.Writer) *CheckedWriter

NewCheckedTerminalWriter detects terminal capabilities from the original destination before adding write accounting. Passing a CheckedWriter to TerminalAwareWriter hides an underlying *os.File and incorrectly disables styling on a real terminal.

func NewCheckedWriter added in v0.1.0

func NewCheckedWriter(destination io.Writer) *CheckedWriter

func (*CheckedWriter) Complete added in v0.1.0

func (w *CheckedWriter) Complete(renderErr error) error

Complete preserves both a renderer failure and an independent destination failure for errors.Is callers.

func (*CheckedWriter) Err added in v0.1.0

func (w *CheckedWriter) Err() error

func (*CheckedWriter) Write added in v0.1.0

func (w *CheckedWriter) Write(p []byte) (int, error)

type Column

type Column struct {
	Header string
	Width  int // 0 = auto
}

Column defines a table column.

type Format

type Format string

Format represents an output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
)

func FormatFromCmd

func FormatFromCmd(cmd *cobra.Command) Format

FormatFromCmd reads the --output flag value from a cobra command.

type ShellRunner added in v0.0.3

type ShellRunner func(stdout, stderr io.Writer, tty bool) error

ShellRunner executes a remote shell with the selected output writers and TTY mode.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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