output

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package output provides rendering utilities for CLI command output.

Index

Constants

View Source
const (
	FormatTable = "table"
	FormatJSON  = "json"
)

Variables

View Source
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.

View Source
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

func AvailableText(available bool) string

AvailableText returns a colorized "Yes" or "No" instead of true/false.

func FormatRelativeTime added in v0.4.0

func FormatRelativeTime(rfc3339 string) string

FormatRelativeTime converts an RFC3339 timestamp to a short relative display. Returns the original string if parsing fails.

func GreenText

func GreenText(s string) string

GreenText returns s rendered in green.

func Hyperlink(text, url string) string

func PipelineStatusColor added in v0.4.0

func PipelineStatusColor(status string) string

func PrintJSON

func PrintJSON(w io.Writer, v any) error

PrintJSON encodes v as indented JSON to w.

func PrintJSONEnvelope added in v0.8.0

func PrintJSONEnvelope(w io.Writer, schemaVersion string, payload any) error

PrintJSONEnvelope writes `{"schemaVersion":"<v>","data":<payload>}` to w.

func PrintJSONErrorEnvelope added in v0.8.0

func PrintJSONErrorEnvelope(w io.Writer, schemaVersion string, err error) error

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

func PrintStyledTable(w io.Writer, headers []string, rows [][]string) error

PrintStyledTable renders a lipgloss table with colored headers, alternating row colors, and no borders. Uses lipgloss for ANSI-aware column width calculation.

func PrintTable

func PrintTable(w io.Writer, headers []string, rows [][]string) error

PrintTable renders a plain-text table for piped or non-TTY output.

func RelativeTime added in v0.8.0

func RelativeTime(t time.Time) string

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

func RenderNoTaskData(w io.Writer, status string) error

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

func ResolveFormat(explicit string) string

ResolveFormat returns the explicit format if provided, otherwise defaults to table. Use -o json for JSON output.

func SCASeverityColor added in v0.10.0

func SCASeverityColor(severity string) string

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

func StatusColor(status string) string

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

func Truncate(s string, maxWidth int) string

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.

func YellowText

func YellowText(s string) string

YellowText returns s rendered in yellow.

Types

type DetailLine

type DetailLine struct {
	Label  string
	Value  string
	Styled string
}

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

type JSONEnvelope struct {
	SchemaVersion string `json:"schemaVersion"`
	Data          any    `json:"data"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL