Documentation
¶
Overview ¶
Package exprfuncs contains functions injected into the expr-lang environment for use in spec expressions (e.g. table columns, body params).
Index ¶
- func Coalesce(vals ...any) any
- func Duration(startMs, endMs any) string
- func EpochMs(v any) string
- func FormatMetadata(m map[string]string) []map[string]string
- func FormatOrder(order, subOrder any) string
- func FormatRoleAssignments(assignments []any) string
- func FormatRoleIds(assignments []any) string
- func FormatTagDisplay(tags map[string]any) string
- func FormatTags(s string) map[string]string
- func HarScopeUrl(auth map[string]any) string
- func IsBlank(v any) bool
- func JsonArray(v []any) string
- func LastPart(s string) string
- func NewPipelineSparkline(isPty bool) func(any) string
- func NewPrLabelColor(enabled bool) func(color, text string) string
- func NewStatusIcon(enabled bool) func(string) string
- func ParseDateMs(v any) string
- func SpaceAfter(s string) string
- func Substr(s string, start, n int) string
- func Truncate(s string, n int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
Coalesce returns the first argument that is non-zero. Zero values are: nil, empty string, integer/float 0, and boolean false.
func Duration ¶
Duration formats the elapsed time between two epoch-millisecond timestamps as a human-readable string ("5m20s" or "42s"). Returns "" when either value is zero. Accepts any numeric type since JSON numbers arrive as float64 in untyped maps.
func EpochMs ¶
EpochMs formats an epoch-millisecond timestamp as "2006-01-02 15:04:05" UTC. Accepts any numeric type. Returns "" for zero or unrecognized input.
func FormatMetadata ¶
FormatMetadata converts a map[string]string (from --set flags) into the []map[string]string shape the Harness metadata API expects: [{key, value}, ...].
func FormatOrder ¶
FormatOrder formats an activity order/sub_order pair as "N" or "N.M". sub_order of 0 is omitted. Accepts any numeric type (JSON numbers arrive as float64).
func FormatRoleAssignments ¶
FormatRoleAssignments converts a roleAssignmentMetadata slice to a JSON array of "roleName (roleScopeLevel)" strings.
func FormatRoleIds ¶
FormatRoleIds converts a roleAssignmentMetadata slice to a JSON array of "roleIdentifier:roleScopeLevel" strings.
func FormatTagDisplay ¶
FormatTagDisplay converts a map[string]string tags value (from the Harness API) into a comma-separated display string. Keys with non-empty values render as "key:value"; keys with empty values render as just "key".
func FormatTags ¶
FormatTags converts a comma-separated list of tag names into the map[string]string shape the Harness API expects: {"tagname": ""}.
func HarScopeUrl ¶
HarScopeUrl returns the HAR UI URL path segment for the given auth map. account-only → "" org-only → "/orgs/{org}" project → "/orgs/{org}/projects/{project}"
func LastPart ¶
LastPart returns the last "/"-delimited segment of s. If s contains no "/", the whole string is returned. Useful when an ID may be prefixed with an optional parent scope (e.g. "pipeline/executionId" or just "executionId").
func NewPipelineSparkline ¶
NewPipelineSparkline returns a sparkline closure using ANSI escapes (pty) or plain ASCII.
func NewPrLabelColor ¶
NewLabelColor returns a function that colorizes text using the nearest basic ANSI color for a Harness Code label color. When enabled is false (non-PTY or machine format), the returned function always returns text unchanged.
func NewStatusIcon ¶
NewStatusIcon returns a function that maps a Harness execution status string to a colored icon string. When enabled is false (non-PTY or machine format), the returned function always returns "".
func ParseDateMs ¶
ParseDateMs converts a date string to epoch milliseconds (as a string). Accepts: YYYY-MM-DD, YYYY-MM-DDTHH:MM:SS, epoch ms (passthrough), or relative durations like "30d" (30 days ago), "2w" (2 weeks ago), "1m" (1 month ago). Returns "" for empty or unrecognized input.
Zoneless dates and times are read in the local zone, so "2026-06-01" means midnight where the user is. Epoch millis and relative spans are absolute.
func SpaceAfter ¶
SpaceAfter returns s + " " if s is non-empty, otherwise "". Useful for conditionally padding an icon before adjacent text.
Types ¶
This section is empty.