render

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package render owns the output contract shared by the verb groups: `-o` dispatch and validation, the table callback, the `{schemaVersion, data}` and `{schemaVersion, error}` envelopes, and the auth-error prefix. Importable only from packages below pkg/cmd/.

Index

Constants

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

The `-o` values.

View Source
const OutputFlagUsage = "Output format: table, json (default: table)"

OutputFlagUsage is the `-o` help text of the verbs that accept json and table.

View Source
const SchemaVersion = "1"

SchemaVersion is the version in every success and error envelope. Bump only when the envelope shape changes in a way scripting consumers must detect.

Variables

This section is empty.

Functions

func HandleAuthError

func HandleAuthError(err error) error

HandleAuthError prefixes a portal.ErrUnauthorized chain with "authentication required: ". The "krci auth login" hint comes from the ErrUnauthorized text. Other errors pass through unchanged.

func HandleError

func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error

HandleError is the error path of an envelope verb: HandleAuthError, then PrintError.

func PrintEnvelope

func PrintEnvelope(w io.Writer, data any) error

PrintEnvelope writes data in the `{schemaVersion, data}` envelope to w.

func PrintError

func PrintError(ios *iostreams.IOStreams, outputFormat string, err error) error

PrintError writes the error envelope to stdout under -o json, unless err reports context cancellation. It adds no auth-error prefix. It returns err, so the root command prints the message on stderr and exits 1, or exits silently if the command was interrupted.

func Render

func Render(ios *iostreams.IOStreams, outputFormat string, data any, renderTable TableRenderer) error

Render dispatches on the `-o` flag. "json" emits the `{schemaVersion, data}` envelope, "table" and the empty default call renderTable, any other value is an unknown-format error.

func RenderBare

func RenderBare(ios *iostreams.IOStreams, outputFormat string, data any, renderTable TableRenderer) error

RenderBare is Render with "json" emitting data as is, without the envelope. Use it only for the bare verbs listed in docs/json-schemas.md; new verbs use Render.

func ResolveFormat

func ResolveFormat(explicit string) string

ResolveFormat returns explicit, or FormatTable when it is empty.

func ValidateJSONOrTable

func ValidateJSONOrTable(format string) error

ValidateJSONOrTable is ValidateOutputFormat with json and table allowed.

func ValidateOutputFormat

func ValidateOutputFormat(format string, allowed ...string) error

ValidateOutputFormat accepts "" (the default) and every value in allowed; the match is case-sensitive. Any other value is an unknown-format error that lists allowed, in order. allowed must not be empty.

Types

type ErrorBody

type ErrorBody struct {
	Message string `json:"message"`
}

ErrorBody carries the human-readable error message.

type ErrorEnvelope

type ErrorEnvelope struct {
	SchemaVersion string    `json:"schemaVersion"`
	Error         ErrorBody `json:"error"`
}

ErrorEnvelope is the error shape of the envelope verbs.

type TableRenderer

type TableRenderer func(w io.Writer, isTTY bool) error

TableRenderer emits the table view. It receives the output writer and the TTY state of stdout.

Jump to

Keyboard shortcuts

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