Skip to content

feat(REL-12755): adding --fields flag#662

Merged
nieblara merged 2 commits intoREL-12754-adding-better-errorsfrom
REL-12755-fields-flags-1
Apr 13, 2026
Merged

feat(REL-12755): adding --fields flag#662
nieblara merged 2 commits intoREL-12754-adding-better-errorsfrom
REL-12755-fields-flags-1

Conversation

@nieblara
Copy link
Copy Markdown
Contributor

@nieblara nieblara commented Mar 18, 2026

Add a --fields persistent flag that filters JSON output to only include specified top-level fields. A flag response can be 50KB+ with targeting configs for every environment. --fields key,name,kind,temporary returns only those fields. Applies to JSON output only. Handles both singular and collection responses (filters each item in items array, preserves totalCount). Error responses are never filtered.


Note

Medium Risk
Moderate risk because it changes the shared output.CmdOutput API and alters default plaintext rendering for several commands, which could break scripts or expected CLI output. JSON filtering is additive but could mask fields if misused or if responses are non-object JSON.

Overview
Adds a new persistent --fields flag (and cliflags.GetFields) to filter JSON command output down to selected top-level fields, supporting both singular responses and items collections while preserving totalCount/_links.

Refactors output.CmdOutput to accept optional field filters and per-resource formatting options, and updates resource/flags/members/config commands to pass ResourceName so plaintext output can render as tables (lists) or key/value blocks (singular) for supported resources.

Hardens plaintext formatting to avoid panics on non-string values, introduces new table/key-value rendering utilities, and expands/updates golden and unit tests to cover the new --fields behavior and changed plaintext output.

Reviewed by Cursor Bugbot for commit c64ba94. Bugbot is set up for automated code reviews on this repo. Configure here.


Related Jira issue: REL-12755: --fields flag for response shaping

@nieblara nieblara changed the title [feat][REL-12755] adding --fields flag feat(REL-12755): adding --fields flag Mar 18, 2026
Copy link
Copy Markdown

@JackDanger JackDanger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation — the filtering logic is solid, collection handling is thoughtful, and the tests are thorough. This is purely additive (opt-in via --fields), so no breaking change concerns. A few design questions:

1. Top-level only filtering leaves the biggest win on the table
The Confluence doc says a flag response can be 50KB+, and the main culprit is the environments object with targeting configs for every environment. But --fields key,name,environments still returns the full 50KB environments blob. The token savings come from not requesting environments at all, which this handles. But if someone wants environments.production.on, they either get the full environments object or nothing.

Not saying you need dot-path filtering in v1, but it's worth noting in the --fields help text that this is top-level only. And: have you considered a complementary --exclude flag? --exclude environments,_links would be the more common use case — "give me everything except the huge stuff."

2. --fields with plaintext is silently ignored
If an agent passes --fields key,name but is in plaintext mode (e.g., FORCE_TTY=1, or explicit --output plaintext), the flag has zero effect with no feedback. An agent won't know its request was ignored. Consider: (a) emitting a stderr warning, or (b) having --fields imply JSON output (like --json does).

3. The CmdOutput function signature is getting heavy

CmdOutput(action, outputKind, input, fields)

And in the very next PR (#663) it becomes:

CmdOutput(action, outputKind, input, fields, opts)

Since you're already adding CmdOutputOpts in #663, consider moving fields into that struct now to avoid the intermediate signature. One refactor instead of two.

4. GetFields silently swallows errors

func GetFields(cmd *cobra.Command) []string {
    fields, err := cmd.Root().PersistentFlags().GetStringSlice(FieldsFlag)
    if err != nil {
        return nil
    }
    return fields
}

If the flag registration is misconfigured, this silently returns nil and filtering never happens. The user gets back 50KB thinking they asked for 3 fields. Probably fine in practice, but a log.Debug would help future debugging.

5. Nice touch: preserving totalCount and _links on collections
This is the right call — pagination metadata shouldn't be filtered. Agents need _links.next to paginate and totalCount to know if there are more pages.

#663)

feat(REL-15756) updating agent friendly and improved rich text output
@nieblara nieblara merged commit 6e02700 into REL-12754-adding-better-errors Apr 13, 2026
11 checks passed
@nieblara nieblara deleted the REL-12755-fields-flags-1 branch April 13, 2026 23:53
nieblara added a commit that referenced this pull request Apr 13, 2026
* [feat] Agent friendly error handling

* feat(REL-12755): adding --fields flag (#662)

* [feat] adding --fields flag

* feat(REL-15756): updating agent friendly and improved rich text output (#663)

feat(REL-15756) updating agent friendly and improved rich text output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants