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. It ensures that we do not mistakenly grab a business parameter also named "fields" by matching the flag's usage string against the global root definition.
func ResolveJQ ¶
ResolveJQ extracts the --jq flag value from the command. It ensures that we only grab the global output filter, not a similarly named business parameter.
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.
Types ¶
type Format ¶
type Format string
const ( FormatJSON Format = "json" FormatTable Format = "table" FormatRaw Format = "raw" FormatPretty Format = "pretty" // FormatNDJSON emits one JSON object per line — friendly for streaming / // piping list results into downstream tools. See ndjson.go. FormatNDJSON Format = "ndjson" // FormatCSV emits RFC-4180 comma-separated values for list-shaped results — // friendly for spreadsheets and non-technical consumers. See csv.go. FormatCSV Format = "csv" )