output

package
v0.1.1-beta Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(format string, args ...interface{})

Error prints a formatted error message to os.Stderr.

func FindByName

func FindByName(data any, field, name string) any

FindByName searches a flattened list response for an item where the given field matches name. Returns the item if found, nil otherwise. Handles both array results and single-object results from the XML-to-JSON parser.

func FlattenAndNormalize

func FlattenAndNormalize(data interface{}) interface{}

FlattenAndNormalize flattens a raw API response and normalizes it to an array. Convenience wrapper for callers that need the processed value (e.g. polling loops).

func FlattenResponse

func FlattenResponse(data interface{}) interface{}

FlattenResponse recursively unwraps single-key objects until it reaches an array or a meaningful multi-key object. For wrapper objects (metadata + one array), it extracts the array. This converts structures like {"TNs":{"TelephoneNumbers":{"Count":"5","TelephoneNumber":[...]}}} into just [...].

func NormalizeToArray

func NormalizeToArray(data interface{}) interface{}

NormalizeToArray ensures list command output is always an array. The XML-to-JSON parser returns a single object when there's one result, which causes silent agent failures. This wraps a lone map in a slice.

func Print

func Print(w io.Writer, format string, data interface{}) error

Print writes data to w in the specified format ("json" or "table").

func PrintTable

func PrintTable(w io.Writer, columns []string, rows []map[string]string)

PrintTable writes a formatted table to w with the given columns and rows.

func Stdout

func Stdout(format string, data interface{}) error

Stdout prints data to os.Stdout in the specified format.

func StdoutAuto

func StdoutAuto(format string, plain bool, data interface{}) error

StdoutAuto prints data to os.Stdout. If plain is true it flattens first; otherwise it uses the specified format string. Table format also flattens to unwrap API response wrappers before rendering. This is the preferred helper for command RunE functions.

func StdoutPlain

func StdoutPlain(data interface{}) error

StdoutPlain prints data to os.Stdout after flattening it to a simplified structure. Intended for script and agent use where deep nesting is noise.

func StdoutPlainList

func StdoutPlainList(format string, plain bool, data interface{}) error

StdoutPlainList is like StdoutAuto for list commands — it always normalizes the result to an array when plain is true, preventing single-item ambiguity. Table format also flattens and normalizes to unwrap API wrappers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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