Documentation
¶
Index ¶
- func ApplyJQ(w io.Writer, payload any, expr string) error
- func ResolveFields(cmd *cobra.Command) string
- func ResolveJQ(cmd *cobra.Command) string
- func SanitizeForTerminal(text string) string
- func SelectFields(payload any, fields []string) any
- func Write(w io.Writer, format Format, payload any) error
- func WriteCommandPayload(cmd *cobra.Command, payload any, fallback Format) error
- func WriteFiltered(w io.Writer, format Format, payload any, fields, jq string) error
- func WriteJSON(w io.Writer, payload any) error
- type Format
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyJQ ¶
ApplyJQ applies a jq expression to a JSON-serialisable payload and writes the results to w. Each result value is written as a separate line of JSON.
The expression is compiled once and evaluated against the normalised payload. Multiple result values (e.g. from `.[]`) are each written as indented JSON followed by a newline.
func ResolveFields ¶
ResolveFields extracts the --fields flag value from the command.
func SanitizeForTerminal ¶
SanitizeForTerminal strips ANSI escape sequences, control characters, and dangerous Unicode from text before it is printed to a terminal. Delegates to the validate package which provides the canonical implementation.
func SelectFields ¶
SelectFields filters a JSON-serialisable payload to include only the specified field names. It works on both objects and arrays:
- Object: returns a new object with only the matching keys.
- Array of objects: returns a new array where each element contains only the matching keys.
- Other types: returned unchanged.
Field names are matched case-insensitively against top-level keys. Nested field selection (e.g. "response.data") is not supported; use --jq for complex queries.
func WriteCommandPayload ¶
func WriteFiltered ¶
WriteFiltered applies field selection and/or jq filtering before writing the payload. If jq is non-empty, the jq result is written directly (bypassing format). If fields is non-empty, the payload is filtered to those fields before normal output.