Documentation
¶
Index ¶
- Constants
- func ConstrainFlag(flag *pflag.Flag, def string, allowed ...string)
- func Fprint(w io.Writer, format Format, data any) error
- func FprintJSONSemantics(w io.Writer, format Format, data any) error
- func NewEnumFlag(def string, allowed ...string) pflag.Value
- func NewFormatFlag(def string, additional ...string) pflag.Value
- func PrintData(cmd *cobra.Command, columns []Column, rows [][]string, data any) error
- func PrintStreamRecord(cmd *cobra.Command, structured any, pretty string) error
- func PrintTable(w io.Writer, columns []Column, rows [][]string) error
- func RunShellOutput(cmd *cobra.Command, interactive, tty bool, run ShellRunner) error
- func TerminalAwareWriter(w io.Writer) io.Writer
- func ValidateShellOutput(cmd *cobra.Command, interactive bool) error
- type CheckedWriter
- type Column
- type Format
- type ShellRunner
Constants ¶
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
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 FprintJSONSemantics ¶ added in v0.0.3
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
NewEnumFlag returns a string flag value restricted to allowed.
func NewFormatFlag ¶ added in v0.0.3
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 ¶
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
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 ¶
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
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
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
type Format ¶
type Format string
Format represents an output format.
func FormatFromCmd ¶
FormatFromCmd reads the --output flag value from a cobra command.