Documentation
¶
Overview ¶
Package output provides rendering utilities for CLI command output.
Index ¶
- Constants
- Variables
- func AvailableText(available bool) string
- func FormatRelativeTime(rfc3339 string) string
- func GreenText(s string) string
- func Hyperlink(text, url string) string
- func PipelineStatusColor(status string) string
- func PrintJSON(w io.Writer, v any) error
- func PrintJSONEnvelope(w io.Writer, schemaVersion string, payload any) error
- func PrintJSONErrorEnvelope(w io.Writer, schemaVersion string, err error) error
- func PrintPlainDetailLines(w io.Writer, lines []DetailLine) error
- func PrintStyledDetailLines(w io.Writer, lines []DetailLine) error
- func PrintStyledTable(w io.Writer, headers []string, rows [][]string) error
- func PrintTable(w io.Writer, headers []string, rows [][]string) error
- func RelativeTime(t time.Time) string
- func RenderDetail[T any](ios *iostreams.IOStreams, outputFormat string, data T, r DetailRenderer[T]) error
- func RenderList[T any](ios *iostreams.IOStreams, outputFormat string, data T, ...) error
- func RenderNoTaskData(w io.Writer, status string) error
- func RenderReason(w io.Writer, result *portal.PipelineRunListResult) error
- func RenderRunInfo(w io.Writer, run *portal.PipelineRunInfo) error
- func ResolveFormat(explicit string) string
- func SCASeverityColor(severity string) string
- func SonarGateStatusColor(status portal.QualityGateStatus) string
- func StatusColor(status string) string
- func Truncate(s string, maxWidth int) string
- func TruncateTaskLogs(result *portal.PipelineRunListResult)
- func YellowText(s string) string
- type DetailLine
- type DetailRenderer
- type JSONEnvelope
- type JSONErrorBody
- type JSONErrorEnvelope
Constants ¶
const ( FormatTable = "table" FormatJSON = "json" )
Variables ¶
var ( HeaderStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(accentColor)).Padding(0, 1) EvenRowStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.BrightWhite) OddRowStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.Color("245")) BorderStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(accentColor)) LabelStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("245")).Width(14) ValueStyle = lipgloss.NewStyle() )
Style definitions shared across all commands.
var ( SectionStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(accentColor)) ReasonLabel = LabelStyle.Width(12) SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Green) FailStyle = lipgloss.NewStyle().Foreground(lipgloss.Red) DimStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("245")) )
Pipeline run output styles.
Functions ¶
func AvailableText ¶
AvailableText returns a colorized "Yes" or "No" instead of true/false.
func FormatRelativeTime ¶ added in v0.4.0
FormatRelativeTime converts an RFC3339 timestamp to a short relative display. Returns the original string if parsing fails.
func PipelineStatusColor ¶ added in v0.4.0
func PrintJSONEnvelope ¶ added in v0.8.0
PrintJSONEnvelope writes `{"schemaVersion":"<v>","data":<payload>}` to w.
func PrintJSONErrorEnvelope ¶ added in v0.8.0
PrintJSONErrorEnvelope writes `{"schemaVersion":"<v>","error":{"message":"<err>"}}` to w.
func PrintPlainDetailLines ¶
func PrintPlainDetailLines(w io.Writer, lines []DetailLine) error
PrintPlainDetailLines renders detail lines as plain text for piped output.
func PrintStyledDetailLines ¶
func PrintStyledDetailLines(w io.Writer, lines []DetailLine) error
PrintStyledDetailLines renders detail lines with lipgloss styling.
func PrintStyledTable ¶
PrintStyledTable renders a lipgloss table with colored headers, alternating row colors, and no borders. Uses lipgloss for ANSI-aware column width calculation.
func PrintTable ¶
PrintTable renders a plain-text table for piped or non-TTY output.
func RelativeTime ¶ added in v0.8.0
RelativeTime renders t as a short "Xm ago"/"Xh ago"/"Xd ago" string, or a Jan-Mon date for anything older than a week.
func RenderDetail ¶
func RenderDetail[T any](ios *iostreams.IOStreams, outputFormat string, data T, r DetailRenderer[T]) error
RenderDetail handles the common format-resolution and output logic for detail commands.
func RenderList ¶
func RenderList[T any]( ios *iostreams.IOStreams, outputFormat string, data T, toRows func(isTTY bool) (headers []string, rows [][]string), ) error
RenderList handles the common format-resolution and output logic for list commands. toRows receives the isTTY flag so callers can apply color only when rendering to a terminal.
func RenderNoTaskData ¶ added in v0.4.0
RenderNoTaskData writes a dim status message for --reason when no task data is available.
func RenderReason ¶ added in v0.4.0
func RenderReason(w io.Writer, result *portal.PipelineRunListResult) error
RenderReason renders pipeline info + task tree + failure diagnosis using lipgloss.
func RenderRunInfo ¶ added in v0.4.0
func RenderRunInfo(w io.Writer, run *portal.PipelineRunInfo) error
RenderRunInfo renders a single pipeline run's info header.
func ResolveFormat ¶
ResolveFormat returns the explicit format if provided, otherwise defaults to table. Use -o json for JSON output.
func SCASeverityColor ¶ added in v0.10.0
SCASeverityColor colorizes a Dep-Track vulnerability severity for TTY rendering. Unknown severities pass through unstyled so future values never break existing renderers.
CRITICAL → red HIGH → yellow MEDIUM → blue LOW → gray INFO → gray UNASSIGNED→ gray
func SonarGateStatusColor ¶ added in v0.8.0
func SonarGateStatusColor(status portal.QualityGateStatus) string
SonarGateStatusColor colorizes a SonarQube quality-gate / issue status value. Unknown values pass through unstyled.
func StatusColor ¶
StatusColor returns the status string with color applied based on its value. Recognized values (from KubeRocketCI CRD status field):
- "created" renders green
- "in_progress" renders yellow
- "failed" renders red
Any other value is returned unstyled.
func Truncate ¶ added in v0.4.0
Truncate shortens s to maxWidth characters, appending "..." if truncated. Returns s unchanged if it fits within maxWidth or maxWidth is 0 (no limit).
func TruncateTaskLogs ¶ added in v0.6.0
func TruncateTaskLogs(result *portal.PipelineRunListResult)
TruncateTaskLogs trims each failed task's log to the last N lines, keeping only the tail that typically contains the real failure reason.
Types ¶
type DetailLine ¶
DetailLine holds one label-value pair for resource detail rendering. When Styled is populated, the styled renderer uses it instead of Value.
type DetailRenderer ¶
type DetailRenderer[T any] struct { Styled func(io.Writer, T) error Plain func(io.Writer, T) error }
DetailRenderer defines styled and plain rendering for a resource detail view.
type JSONEnvelope ¶ added in v0.8.0
JSONEnvelope wraps a success payload with the shared schemaVersion/data contract. Used by commands that need a stable JSON output shape (e.g. `krci sonar *`).
type JSONErrorBody ¶ added in v0.8.0
type JSONErrorBody struct {
Message string `json:"message"`
}
JSONErrorBody carries the human-readable error message.
type JSONErrorEnvelope ¶ added in v0.8.0
type JSONErrorEnvelope struct {
SchemaVersion string `json:"schemaVersion"`
Error JSONErrorBody `json:"error"`
}
JSONErrorEnvelope wraps an error message with the shared schemaVersion/error contract.