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 ≤ 2) are shown with ShortValueTemplate. // 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 compact widths.
// 1 = always shown in compact, 2 = always shown in compact,
// 3+ = full table only. 0 is treated as 1.
Priority int
// ShortValueTemplate is an alternative Go template used at compact
// widths. If empty, the regular ValueTemplate is used.
ShortValueTemplate string
// ColorFunc applies color formatting to the cell value.
// If nil, no color formatting is applied.
ColorFunc func(string) string
}
PrettyColumn extends Column with priority for responsive column dropping.
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 3 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 name of the column to group cards by
// in the card layout. Each distinct value becomes a section header.
// If empty, cards are rendered ungrouped with the first column as card title.
CardGroupColumn string
// FullThreshold is the terminal width at or above which the full layout
// is used (all columns, full text). Defaults to DefaultFullThreshold (100).
FullThreshold int
// CompactThreshold is the terminal width at or above which the compact
// layout is used (Priority ≤ 2 columns, ShortValueTemplate).
// Below this the card layout is used.
// Defaults to DefaultCompactThreshold (60).
CompactThreshold int
}
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
}