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 ResolveJQ ¶
ResolveJQ extracts the --jq flag value from the command. It checks local flags, inherited flags, and root persistent flags because --jq is registered as a root PersistentFlag.
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, following the gh CLI convention:
- If the payload is an array of objects, filter each element.
- If the payload is an object containing a "data list" (a nested array under a well-known key like "value", "items", "data", "records", etc.), filter each element of that list.
- Otherwise, filter top-level keys.
This approach lets callers write `--fields title,memberCount` and get the right result regardless of the response envelope structure. Field names are matched case-insensitively.
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.