Documentation
¶
Overview ¶
Package discovery holds helpers shared by the deployment-discovery verbs (`krci env list`, `krci env get`, `krci project deployments`): DNS-1123 validation, output-format dispatch, JSON envelope rendering, and shared error promotion. Placed under `pkg/cmd/internal/` so Go enforces package visibility: only packages below `pkg/cmd/...` may import it.
Index ¶
- Constants
- func ColorForArgoStatus(s string) string
- func ExpandIngressRows(cells []string, ingressLines []string) [][]string
- func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error
- func HostnameFromURL(u string) string
- func IngressLines(urls []string, isTTY bool) []string
- func OptCell(s *string) string
- func OptStatusCell(s *string, isTTY bool) string
- func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]string) error
- func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, ...) error
- func ShortDigestCell(digest *string) string
- func ValidateCluster(cluster string) error
- func ValidateDeployment(deployment string) error
- func ValidateEnv(env string) error
- func ValidateOutputFormat(format string) error
- func ValidateProject(project string) error
- type TableRenderer
Constants ¶
const MaxIngressHostLen = 50
MaxIngressHostLen caps the visible width of an ingress hostname in table mode (mirrors the pipelinerun-list approach of truncating long names). The OSC 8 hyperlink target carries the full URL regardless.
const SchemaVersion = "1"
SchemaVersion is the shared JSON envelope version for every deployment- discovery verb. Bump only when the envelope shape changes in a way scripting consumers must detect.
const ShortDigestLen = 15
ShortDigestLen is the maximum length of an image digest as shown in table mode: `sha256:` (7 chars) + first 8 hex chars = 15 visible characters.
Variables ¶
This section is empty.
Functions ¶
func ColorForArgoStatus ¶
ColorForArgoStatus renders an ArgoCD health-status string with a TTY color. healthy → green, degraded/missing → red, progressing → blue (matching the running-pipeline color in `output.PipelineStatusColor`). Anything else (including suspended/unknown) passes through unstyled.
func ExpandIngressRows ¶
ExpandIngressRows turns one logical row (cells without INGRESS) plus a list of ingress lines into N visual rows. The first visual row carries the full data; subsequent rows blank out every cell except INGRESS, producing a vertically-stacked layout:
project1 … ingress1
ingress2
project2 … ingress1
When ingressLines is empty, a single row is emitted with "-" in INGRESS.
func HandleError ¶
HandleError promotes portal.ErrUnauthorized to the shared "run krci auth login" message and — when `-o json` is selected — also writes the `{schemaVersion, error: { message }}` envelope to stdout so scripting consumers get a structured error alongside the exit-1 signal.
func HostnameFromURL ¶
HostnameFromURL strips the scheme + path from a URL, returning just the host. Falls back to the original string if no scheme separator is present.
func IngressLines ¶
IngressLines renders an ingress-URL slice as one cell per URL. Each line is the hostname (no scheme), truncated to MaxIngressHostLen visible characters and wrapped in an OSC 8 hyperlink (full URL preserved as the link target) when isTTY. Returns nil when urls is empty; callers display a single "-" row in that case.
func OptCell ¶
OptCell renders an optional string field as the dereferenced value, or "-" when the pointer is nil or the value is empty.
func OptStatusCell ¶
OptStatusCell renders an ArgoCD health-status cell with optional TTY color. "-" when the pointer is nil or the value is empty.
func PrintTable ¶
PrintTable is the shared TTY/non-TTY dispatcher.
func Render ¶
func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, renderTable TableRenderer) error
Render dispatches on the `-o` flag: emit `{schemaVersion, data}` envelope for `-o json`, invoke the supplied TableRenderer for `-o table` (default), or return a validation error.
func ShortDigestCell ¶
ShortDigestCell shortens a sha256 digest for table display: keeps the `sha256:` prefix plus the first 8 hex chars (ShortDigestLen visible chars). Returns "-" when the pointer is nil or the value is empty.
func ValidateCluster ¶
ValidateCluster rejects values that fail DNS-1123 label validation when the `--cluster` flag is supplied with a non-empty value. Empty is allowed since the flag is optional.
func ValidateDeployment ¶
ValidateDeployment rejects values that fail DNS-1123 label validation. Used by both the positional `<deployment>` (env get) and the `--deployment` flag value (env list).
func ValidateEnv ¶
ValidateEnv rejects values that fail DNS-1123 label validation. <env> maps to Stage.spec.name (a short user-facing identifier like "dev", "stage", "prod").
func ValidateOutputFormat ¶
ValidateOutputFormat rejects `-o` values other than "", "table", or "json".
func ValidateProject ¶
ValidateProject rejects project names that fail DNS-1123 label validation. Used by `krci project deployments <project>`.