format

package
v3.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BucketStyles = map[ExecutionStatusBucket]BucketStyle{
	StatusSuccess: {"✓", "\x1b[32m▪\x1b[0m", "+", 32, "82"},
	StatusSkipped: {"↷", "\x1b[90m▪\x1b[0m", "-", 90, "243"},
	StatusFailed:  {"✗", "\x1b[31m▪\x1b[0m", "x", 31, "196"},
	StatusRunning: {"▶", "\x1b[34m▸\x1b[0m", ">", 36, "39"},
	StatusWaiting: {"⊘", "\x1b[33m◌\x1b[0m", "o", 33, "220"},
	StatusNoData:  {"○", "\x1b[90m·\x1b[0m", ".", 90, "240"},
}

BucketStyles holds display properties for each execution status bucket.

Functions

func ApplyColumns

func ApplyColumns(fields []spec.FieldDef, defaultCols []spec.TableColumn, s string) ([]spec.TableColumn, error)

ApplyColumns resolves a --columns string against a set of known FieldDefs into []TableColumn.

Token forms (comma-separated, or JSON array):

"id"         → look up field by ID; error if not found
"id:expr"    → ad-hoc column: label auto-derived from id (underscores→spaces, title-case), expr literal

Sigil prefix:

"+id"        → add to default set (modify mode)
"-id"        → remove from default set by ID (modify mode)

If ALL tokens carry a sigil, modify mode applies against the default columns. If ANY token is plain, replace mode: the result is exactly those columns. Mixing sigiled and plain tokens is an error.

func BuildTable

func BuildTable(tspec *spec.TableSpec, itemsExpr string, resp any, noHeaders bool, exprEnv map[string]any) (table.Writer, error)

BuildTable evaluates itemsExpr against resp to locate the row slice, then renders the columns defined in spec. Use "it" as itemsExpr for bare array responses. exprEnv is the base expr-lang environment; "it" is injected per row for column expressions.

func EnvColumnsFor

func EnvColumnsFor(noun string) string

EnvColumnsFor returns the --columns override configured via hbase.EnvColumns for the given noun, or "" if the env var is unset or has no entry for that noun. Callers should only consult this when --columns wasn't passed explicitly, since the flag always wins.

Format: semicolon-separated "noun=columns" entries, e.g.

HARNESS_CLI_COLUMNS="pipeline=id,name,status;execution=id,status,started"

The "columns" half uses the exact same syntax as --columns (including +/- modify mode) and is split from the noun on the first "=" only, so a column expression containing "=" (e.g. "status:it.status == 'success'") is preserved intact.

func FormatArrayOutput

func FormatArrayOutput(flags cmdctx.FormatFlags, isPty bool, data any, itemsExpr string, defaultTspec *spec.TableSpec, fields []spec.FieldDef, exprEnv map[string]any, meta *cmdctx.PageMeta) error

FormatArrayOutput renders a list response (table, json, jsonl, csv, tsv). itemsExpr is an expr-lang expression that resolves the row slice; "it" is bound to the full response. defaultTspec is the command's declared table layout; may be nil. exprEnv is the base expr-lang environment (ctx, flags, auth, helpers); "it" is injected per row for columns. meta, when non-nil, causes paging information and/or a notice to be printed after the table.

func FormatFieldsOutput

func FormatFieldsOutput(flags cmdctx.FormatFlags, data any, itemExpr string, fields []spec.FieldDef, fieldIDs []string, exprEnv map[string]any) error

FormatFieldsOutput extracts a comma-separated list of field IDs from a single-item response and prints their values tab-separated on one line. Designed for shell $() capture. Unknown field IDs are silently skipped (empty string).

func FormatSingleOutput

func FormatSingleOutput(flags cmdctx.FormatFlags, isPty bool, data any, itemExpr string, yamlPickExpr string, yamlExclude []string, textFmt TextFormatterFn, exprEnv map[string]any) error

FormatSingleOutput renders a single-item response (get, execute, …). itemExpr is an expr-lang expression unwrapped unless --raw is set. Use "it" for bare responses. yamlPickExpr, when non-empty, enables --format yaml and defines which subtree to emit; evaluated from the raw response root. textFmt, when non-nil, is used when format is "text". "it" is bound to the full response; ctx, auth, flags, and helpers are also available via exprEnv.

func NewTable

func NewTable() table.Writer

NewTable returns a table writer with the standard style: no borders, bold headers, separator line.

func OpenWriter

func OpenWriter(outFile string) (io.Writer, func(), error)

func WriteLabeledValues

func WriteLabeledValues(w io.Writer, items []LabeledValue)

WriteLabeledValues writes label/value pairs aligned by the longest label. Each label is suffixed with ":" and padded so all values line up.

Types

type BucketStyle

type BucketStyle struct {
	NodeGlyph      string // ✓ ✗ ▶ ⊘ ○  — execution tree / status icons
	SparklinePty   string // pre-built ANSI-colored glyph for PTY sparklines
	SparklinePlain string // plain ASCII for non-PTY sparklines
	AnsiCode       int    // ANSI 16-color code; cast to console.Color for console.WithColor
	LipglossColor  string // 256-color code for lipgloss.Color()
}

BucketStyle holds all display properties for a status bucket.

type ColumnParseError

type ColumnParseError struct {
	Input string
	Err   error
}

ColumnParseError is returned when a column spec string cannot be parsed.

func (*ColumnParseError) Error

func (e *ColumnParseError) Error() string

func (*ColumnParseError) Unwrap

func (e *ColumnParseError) Unwrap() error

type ExecutionStatusBucket

type ExecutionStatusBucket int

ExecutionStatusBucket is the broad category an execution status maps to.

const (
	StatusSuccess ExecutionStatusBucket = iota
	StatusSkipped
	StatusFailed
	StatusRunning
	StatusWaiting
	StatusNoData
)

func ClassifyExecutionStatus

func ClassifyExecutionStatus(status string) ExecutionStatusBucket

ClassifyExecutionStatus maps a Harness execution status string (PascalCase or legacy SCREAMING_SNAKE_CASE) to one of the five display buckets. Also accepts the lowercase Harness Code check-status vocabulary (pending, running, success, failure, failure_ignored, error).

type LabeledValue

type LabeledValue struct {
	Label string
	Value string
}

LabeledValue is a label/value pair for use with WriteLabeledValues.

type TextFormatterFn

type TextFormatterFn = cmdctx.TextFormatterFn

TextFormatterFn is an alias for the canonical type in cmdctx.

func BuildTextFieldFormatter

func BuildTextFieldFormatter(fields []spec.FieldDef, header, footer string, interpolate func(tmpl string, item any) string) TextFormatterFn

BuildTextFieldFormatter returns a TextFormatterFn driven by a declarative field list with optional header and footer templates. interpolate resolves {{expr}} in header/footer against the response item — callers supply this to avoid an import cycle with the registry's resolvePath. Supported Format values: "epoch_ms", "bool", "json_array", "role_assignments".

Jump to

Keyboard shortcuts

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