Documentation
¶
Index ¶
- func FormatDuration(seconds int) string
- func FormatDurationFloat(seconds float64) string
- func FormatTime(ts instant) string
- func FormatTimeValue(v any) (string, bool)
- func NullUnsetInstants(v any) any
- func Truncate(s string, maxLen int) string
- type Column
- type Format
- type JSONPrinter
- type Printer
- type TOONPrinter
- type TablePrinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration formats seconds into human-readable duration (e.g., "2m 30s", "1h 15m").
func FormatDurationFloat ¶
FormatDurationFloat formats float64 seconds into human-readable duration.
func FormatTime ¶
func FormatTime(ts instant) string
FormatTime formats an instant as local wall-clock time, or "-" when unset.
func FormatTimeValue ¶ added in v1.3.12
FormatTimeValue formats v with FormatTime when v is an instant (go-flashduty Timestamp/TimestampMilli), returning ok=false for any other value. It lets the generic table renderer format timestamp fields it reaches by reflection without importing the unexported instant type or duplicating the layout.
func NullUnsetInstants ¶ added in v1.4.5
NullUnsetInstants returns a copy of v in which every unset (zero) SDK timestamp — go-flashduty Timestamp/TimestampMilli — is replaced by nil, so JSON output renders it as null instead of the bare integer 0.
The SDK's Timestamp.MarshalJSON emits a quoted RFC3339 string for a set value but the bare integer 0 for the unset sentinel, so one field switches JSON type depending on record state (e.g. an alert's end_time is 0 while the alert is active but "2026-05-28T08:00:00Z" once recovered). That breaks jq arithmetic over mixed-state results. Set values keep their original typed value, so their custom MarshalJSON (and byte shape) is untouched; non-timestamp zero integers are untouched too.
The transform rebuilds only the subtrees that contain a timestamp, via reflect.StructOf on the same field names/tags/order, so the encoded output keeps the original struct field order. TOON and table output are unaffected (they render the sentinel through String(), already always a string).
Types ¶
type Format ¶ added in v1.3.1
type Format int
Format selects how command output is serialized.
const ( // FormatTable renders human-readable aligned columns (the default). FormatTable Format = iota // FormatJSON renders pretty-printed JSON. FormatJSON // FormatTOON renders Token-Oriented Object Notation — a compact // serialization that drops the per-row repeated keys JSON emits for // uniform arrays, materially reducing token count for list output. FormatTOON )
func (Format) Structured ¶ added in v1.3.1
Structured reports whether the format is a machine-readable dump (JSON or TOON) rather than the human table view. Table footers, detail views, and interactive prompts are suppressed when the output is structured.
type JSONPrinter ¶
type JSONPrinter struct {
// contains filtered or unexported fields
}
JSONPrinter prints data as pretty-printed JSON.
type TOONPrinter ¶ added in v1.3.1
type TOONPrinter struct {
// contains filtered or unexported fields
}
TOONPrinter prints data as TOON (Token-Oriented Object Notation). It routes through toon.Marshal directly — the same encoder the Flashduty SDKs and MCP server use, so the on-the-wire encoding stays identical across tools.
type TablePrinter ¶
type TablePrinter struct {
// contains filtered or unexported fields
}
TablePrinter prints data as aligned tables.