Documentation
¶
Index ¶
- Constants
- func FormatTime(t *time.Time, format string) string
- func JSONOutput(w io.Writer, data any) error
- func List[T any](p *Printer, headers []string, items []T, rowFunc func(T) []string) error
- func YAMLOutput(w io.Writer, data any) error
- type CommandOutput
- type Format
- type Printer
- func (p *Printer) Errorf(format string, args ...any)
- func (p *Printer) IsStructured() bool
- func (p *Printer) NewTable(headers ...string) *Table
- func (p *Printer) Print(msg string)
- func (p *Printer) Printf(format string, args ...any)
- func (p *Printer) Structured(data any) error
- func (p *Printer) WithFormat(f Format) *Printer
- type Table
Constants ¶
const ( // TimestampDisplay is for human-readable output in terminal. TimestampDisplay = "2006-01-02 15:04:05" // TimestampISO is for JSON/machine output (RFC3339). TimestampISO = time.RFC3339 )
Timestamp format constants for consistent display across commands.
Variables ¶
This section is empty.
Functions ¶
func FormatTime ¶
FormatTime formats a time pointer for display. Returns "-" if the time is nil or zero.
func JSONOutput ¶
JSONOutput writes data as indented JSON to the writer.
Types ¶
type CommandOutput ¶
CommandOutput is the interface for cobra.Command output methods.
type Format ¶
type Format string
Format specifies the output format.
func ParseFormat ¶
ParseFormat converts a string to Format, defaulting to FormatText.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer provides consistent output formatting for CLI commands.
func NewPrinter ¶
func NewPrinter(cmd CommandOutput) *Printer
NewPrinter creates a Printer from a cobra.Command (or any CommandOutput).
func (*Printer) IsStructured ¶
IsStructured returns true if the printer is in JSON or YAML mode.
func (*Printer) Structured ¶
Structured writes data as JSON or YAML based on the printer's format.
func (*Printer) WithFormat ¶
WithFormat returns a new Printer with the specified format.