Documentation
¶
Index ¶
- Constants
- func AddOutputFlag(f *pflag.FlagSet, s *string, supportedFormats []Format, defaultFormat Format)
- func AddOutputParam(cmd *cobra.Command, supportedFormats []Format, defaultFormat Format) *cobra.Command
- func AddQueryParam(cmd *cobra.Command)
- func ApplyQuery(data any, query string) (any, error)
- func EventForMessage(message string) contracts.EventEnvelope
- func TabAlign(selections []string, padding int) ([]string, error)
- func WithBackticks(s string) string
- func WithBold(text string, a ...any) string
- func WithErrorFormat(text string, a ...any) string
- func WithGrayFormat(text string, a ...any) string
- func WithHighLightFormat(text string, a ...any) string
- func WithHintFormat(text string, a ...any) string
- func WithHyperlink(url string, text string) string
- func WithLinkFormat(link string, a ...any) string
- func WithMarkdown(markdownText string) string
- func WithSuccessFormat(text string, a ...any) string
- func WithUnderline(text string, a ...any) string
- func WithWarningFormat(text string, a ...any) string
- type Column
- type DynamicMultiWriter
- type EnvVarsFormatter
- type Format
- type Formatter
- type JsonFormatter
- type Link
- type NoneFormatter
- type PrettyColumn
- type PrettyTableFormatter
- type PrettyTableFormatterOptions
- type Queryable
- type TableFormatter
- type TableFormatterOptions
Constants ¶
const ( // DefaultFullThreshold is the terminal width at or above which all columns // are shown with full text values. DefaultFullThreshold = 100 // DefaultCompactThreshold is the terminal width at or above which only // high-priority columns (Priority ≤ compactPriorityThreshold) are shown. // Below this value the card layout is used. DefaultCompactThreshold = 60 )
Width breakpoint constants for responsive layout selection.
const ( TableColumnMinWidth = 10 TableTabSize = 4 TablePadSize = 2 TablePadCharacter = ' ' TableFlags = 0 )
Variables ¶
This section is empty.
Functions ¶
func AddOutputFlag ¶
func AddOutputParam ¶
func AddQueryParam ¶
AddQueryParam adds a hidden --query flag to the command for JMESPath filtering. This should only be called for commands that support JSON output format.
func ApplyQuery ¶
ApplyQuery applies a JMESPath query to the given data and returns the filtered result. If the query is empty, the original data is returned unchanged. If the query is invalid, an error with a hint to JMESPath documentation is returned.
func EventForMessage ¶
func EventForMessage(message string) contracts.EventEnvelope
jsonObjectForMessage creates a json object representing a message. Any ANSI control sequences from the message are removed. A trailing newline is added to the message.
func TabAlign ¶
TabAlign transforms translates tab-separated columns in input into properly aligned text with the given padding for separation. For more information, refer to the tabwriter package.
func WithBackticks ¶
WithBackticks wraps text with the backtick (`) character.
func WithErrorFormat ¶
func WithGrayFormat ¶
func WithHighLightFormat ¶
withHighLightFormat creates string with highlight-looking color
func WithHintFormat ¶
func WithHyperlink ¶
WithHyperlink wraps text with the colored hyperlink format escape sequence. When stdout is not a terminal (e.g., in CI/CD pipelines like GitHub Actions), it returns the plain URL without escape codes to avoid displaying raw ANSI sequences.
func WithLinkFormat ¶
withLinkFormat creates string with hyperlink-looking color
func WithMarkdown ¶
WithMarkdown converts markdown to terminal-friendly colorized output using glamour. This provides rich markdown rendering including bold, italic, code blocks, headers, etc.
func WithSuccessFormat ¶
func WithUnderline ¶
func WithWarningFormat ¶
Types ¶
type DynamicMultiWriter ¶
type DynamicMultiWriter struct {
// contains filtered or unexported fields
}
DynamicMultiWriter allows adding/removing writers dynamically
func NewDynamicMultiWriter ¶
func NewDynamicMultiWriter(writers ...io.Writer) *DynamicMultiWriter
func (*DynamicMultiWriter) AddWriter ¶
func (d *DynamicMultiWriter) AddWriter(w io.Writer)
AddWriter adds a new writer
func (*DynamicMultiWriter) RemoveWriter ¶
func (d *DynamicMultiWriter) RemoveWriter(target io.Writer)
RemoveWriter removes a writer
type EnvVarsFormatter ¶
type EnvVarsFormatter struct {
}
func (*EnvVarsFormatter) Kind ¶
func (f *EnvVarsFormatter) Kind() Format
type Formatter ¶
func NewFormatter ¶
type JsonFormatter ¶
type JsonFormatter struct {
Query string
}
func (*JsonFormatter) Kind ¶
func (f *JsonFormatter) Kind() Format
func (*JsonFormatter) QueryFilter ¶
func (f *JsonFormatter) QueryFilter(obj any) (any, error)
QueryFilter applies the JMESPath query (if any) to the given object. When no query is configured, the object is returned unchanged.
type NoneFormatter ¶
type NoneFormatter struct{}
func (*NoneFormatter) Kind ¶
func (f *NoneFormatter) Kind() Format
type PrettyColumn ¶ added in v1.25.0
type PrettyColumn struct {
Column
// Priority controls column visibility at the compact breakpoint.
// 1 and 2 are shown at compact; 3+ are full-table only. 0 is treated as 1.
Priority int
// CardValueTemplate is an alternative Go template used by the card layout.
// If empty, the regular ValueTemplate is used. It allows a column to omit
// redundant values in cards (e.g. a "latest" version that equals the
// installed one) while still rendering them in the table layouts.
CardValueTemplate string
// ColorFunc applies color formatting to the cell value. If nil, no color
// formatting is applied.
ColorFunc func(string) string
// Truncatable allows the value to be shortened with an ellipsis to fit the
// available width. At least minVisibleChars characters are kept.
Truncatable bool
// Wrappable allows the value to wrap onto at most maxWrapLines lines before
// being truncated. Used for identifier columns (e.g. NAME) where wrapping is
// preferred over truncation.
Wrappable bool
// CardTitle renders this column's value as the card's bold, highlighted
// title line (without a label) in the card layout, excluding it from the
// labeled card fields.
CardTitle bool
}
PrettyColumn extends Column with responsive layout metadata.
type PrettyTableFormatter ¶ added in v1.25.0
type PrettyTableFormatter struct {
// ConsoleWidthFn returns the current terminal width. Defaults to getConsoleWidth.
ConsoleWidthFn func() int
}
PrettyTableFormatter renders tabular data with responsive breakpoints. It supports three layout modes based on terminal width: full table, compact table (fewer columns), and card layout.
func (*PrettyTableFormatter) Kind ¶ added in v1.25.0
func (f *PrettyTableFormatter) Kind() Format
type PrettyTableFormatterOptions ¶ added in v1.25.0
type PrettyTableFormatterOptions struct {
Columns []PrettyColumn
// CardGroupColumn is the heading of the column to group cards by in the card
// layout. Each distinct value becomes a section header. If empty, cards are
// rendered ungrouped.
CardGroupColumn string
// FullThreshold is the terminal width at or above which the full layout is
// used. Defaults to DefaultFullThreshold (100).
FullThreshold int
// CompactThreshold is the terminal width at or above which the compact
// layout is used. Below this the card layout is used.
// Defaults to DefaultCompactThreshold (60).
CompactThreshold int
// ResponsiveColumnHint enables the header-only "···" column and the
// "Showing N of M columns" / "Resize the terminal..." hint message in the
// table layouts when columns are hidden or values are truncated.
ResponsiveColumnHint bool
// ForceCards renders the card layout regardless of terminal width.
ForceCards bool
}
PrettyTableFormatterOptions configures the pretty table formatter.
type Queryable ¶
Queryable is an optional interface that a Formatter may implement to support JMESPath filtering on arbitrary objects. Console messages (e.g. error output) use this to apply --query without going through the full Format() pipeline.
type TableFormatter ¶
type TableFormatter struct {
}
func (*TableFormatter) Kind ¶
func (f *TableFormatter) Kind() Format
type TableFormatterOptions ¶
type TableFormatterOptions struct {
Columns []Column
}