Documentation
¶
Overview ¶
Package cli provides shared CLI utilities such as table formatting helpers.
Index ¶
- Variables
- func AttributesToAnyMap(attrs map[string]string) map[string]any
- func IsInteractive(f *os.File) bool
- func MarkdownEscape(s string) string
- func NewTable(headers ...any) table.Table
- func Paginate[T any](seq iter.Seq2[T, error], cfg PagerConfig[T]) error
- func StringMapToAnyMap(m map[string]string) map[string]any
- func TruncateString(s string, maxWidth int) string
- type PagerConfig
Constants ¶
This section is empty.
Variables ¶
var MarkdownTemplateFuncs = template.FuncMap{ "mdEscape": MarkdownEscape, }
MarkdownTemplateFuncs are the helper funcs available in every glamour-fed markdown template. Pass to `template.New(...).Funcs(...)`.
Functions ¶
func AttributesToAnyMap ¶
AttributesToAnyMap converts cobra's StringToString flag value into the map[string]any shape the API inputs expect. Returns nil when no entries are present so the field marshals to JSON null and the server treats it as absent rather than rejecting an empty Map.
func IsInteractive ¶
IsInteractive reports whether f is attached to a terminal. It is the single gate used to decide between the interactive pager and plain streaming.
func MarkdownEscape ¶
MarkdownEscape escapes markdown punctuation in user-supplied strings before they land in a template that gets fed to glamour. Without this, characters like `_` in `cost_center` open emphasis spans and the renderer mangles the output (e.g. `cost_center` displays as `cost_****center`).
func Paginate ¶
Paginate renders a paginated iterator.
When Out is an interactive terminal it launches a scrollable table that lazily pulls more rows as the cursor approaches the end, so a multi-thousand-row list never fetches more than the user actually scrolls through. The user quits with q / esc / ctrl-c.
When Out is not a terminal (a pipe, a file, CI), it drains the iterator and writes a plain table — keeping scripts and output redirection working. The caller is responsible for routing structured (--output json) requests elsewhere before reaching here.
func StringMapToAnyMap ¶
StringMapToAnyMap preserves an existing attribute map (read off a Project, Environment, or Component) when an update command needs to round-trip it without modification.
func TruncateString ¶
TruncateString truncates a string to maxWidth runes, handling emojis correctly
Types ¶
type PagerConfig ¶
type PagerConfig[T any] struct { // Columns are the table header titles. Columns []string // Row maps one item to its cells. The returned slice must align with Columns. Row func(T) []string // Out is the destination; defaults to os.Stdout when nil. Used both to // decide whether output is interactive and as the render target. Out *os.File // PageSize is how many rows are pulled from the iterator per batch in // interactive mode. Zero uses a sensible default. PageSize int }
PagerConfig describes how a paginated result set is rendered by Paginate.