Skip to content

feat: --show-only flag and audience JSON pretty-print#40

Merged
joalves merged 15 commits into
mainfrom
feat/show-only-and-audience-json
May 25, 2026
Merged

feat: --show-only flag and audience JSON pretty-print#40
joalves merged 15 commits into
mainfrom
feat/show-only-and-audience-json

Conversation

@joalves
Copy link
Copy Markdown
Collaborator

@joalves joalves commented May 25, 2026

Summary

  • audience is now parsed to a real JSON object in formatExtraField, so abs exp get <id> --show audience -o json (and -o yaml) emit a nested object instead of an escaped string blob.
  • Adds --show-only <fields...> everywhere --show exists today — exp get, exp list, exp custom-fields, plus goals / metrics / users / teams / segments / customfields get & list. Replaces default columns entirely; mutually exclusive with --show and --exclude (throws at the command layer).
  • -o rendered on exp get now honors --show / --exclude / --show-only. The filtered summary drives every section (header table, audience block, variants, metric sections, custom-field sections). Default rendered output is preserved: when --show-only is absent, audience + all custom-field titles are injected as implicit extras so today's output is unchanged. With --exclude audience the audience section disappears; with --show-only id name only the title, a two-row table, and footer render.

Test plan

  • bun run test -- --run — 2416 passed (+29 new), 4 skipped
  • bun run lint — clean
  • bun run typecheck — clean
  • Smoke test on real cluster: abs --profile latam exp get 2812 -o json --show audience shows audience as nested object
  • abs --profile latam exp get 2812 -o rendered matches pre-change output byte-for-byte
  • abs --profile latam exp get 2812 -o rendered --show-only id name audience renders only the requested minimum
  • abs --profile latam exp get 2812 --show-only id name --show audience exits non-zero with the mutual-exclusion error

Summary by CodeRabbit

  • New Features

    • Added --show-only <fields...> to many commands (experiments, goals, metrics, segments, teams, users, custom fields, list helpers) to return only specified fields; mutually exclusive with --show/--exclude.
    • CLI experiment output embeds screenshots as inline placeholders.
  • Improvements

    • Summaries support dot-paths and a strict “only fields” mode; JSON-like extra-field values are auto-parsed.
  • Refactor

    • Improved summary/header ordering, date fallback and object formatting across output modes.
  • Tests

    • Expanded unit and CLI tests for show-only, dot-paths, JSON parsing and formatting.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fe45ac8d-784a-4261-8980-9a58cabbf3fc

📥 Commits

Reviewing files that changed from the base of the PR and between b01c053 and 75ced70.

📒 Files selected for processing (6)
  • src/api-client/entity-summary.test.ts
  • src/api-client/entity-summary.ts
  • src/api-client/experiment-summary.test.ts
  • src/api-client/experiment-summary.ts
  • src/api-client/format-helpers.test.ts
  • src/api-client/format-helpers.ts

Walkthrough

This PR introduces a new --show-only CLI option across multiple commands and extends the underlying summarization and filtering helpers to respect field-only projections. The option restricts API responses to specified fields only and is validated as mutually exclusive with existing --show and --exclude options. Core API functions (applyShowExclude, summarizeExperiment, summarizeExperimentRow) gain an optional onlyFields parameter that, when set, constructs responses containing only the requested fields and bypasses standard exclude logic. The PR also adds JSON parsing for the audience field in extra-field formatting. The experiments get command receives the most substantial changes, including rendering refactors for header ordering, custom-field filtering, and unified timestamp handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • absmartly/cli-ts#2: Introduced the original applyShowExclude, summarizeExperiment, and summarizeExperimentRow functions that this PR extends with the new onlyFields/--show-only projection logic.

Poem

🐰 I hop through fields both wide and narrow,
I nibble extras to show only what's hallowed,
Dot-paths I fetch and audience strings I parse,
CLI flags aligned like carrots in a row — not sparse,
A tiny rabbit cheer for focused, tidy shows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: addition of --show-only flag and audience JSON pretty-print support across multiple commands and core modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/show-only-and-audience-json

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api-client/entity-summary.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api-client/entity-summary.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/api-client/experiment-summary.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 3 others

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/users/index.ts`:
- Around line 141-143: The avatar rendering breaks because
summarizeUserRow/applyShowExclude may drop the id when showOnly is used; change
the avatar lookup to use the original source user identity rather than the
filtered row: when mapping users (the users array passed into summarizeUserRow
and applyShowExclude) either attach the original id (e.g., a hidden __origId) to
each produced row or, better, keep and use the original users array for avatar
lookup (use users[dataIdx].id) when rendering avatars instead of
rows[dataIdx].id; update any code that currently references rows[dataIdx].id
(avatar rendering code) to read the id from the preserved source (users) or the
added __origId so avatars remain stable even when showOnly omits id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: babf4324-86fe-45d5-a23f-e6b4e223a85f

📥 Commits

Reviewing files that changed from the base of the PR and between 690880f and 48a12da.

📒 Files selected for processing (26)
  • .gitignore
  • src/api-client/entity-summary.test.ts
  • src/api-client/entity-summary.ts
  • src/api-client/experiment-summary.test.ts
  • src/api-client/experiment-summary.ts
  • src/api-client/format-helpers.test.ts
  • src/api-client/format-helpers.ts
  • src/commands/customfields/index.ts
  • src/commands/experiments/custom-fields.ts
  • src/commands/experiments/get.test.ts
  • src/commands/experiments/get.ts
  • src/commands/experiments/list.ts
  • src/commands/goals/index.ts
  • src/commands/metrics/index.ts
  • src/commands/segments/index.ts
  • src/commands/teams/index.ts
  • src/commands/users/index.ts
  • src/core/customfields/get.ts
  • src/core/experiments/custom-fields.ts
  • src/core/experiments/get.test.ts
  • src/core/experiments/get.ts
  • src/core/experiments/list.test.ts
  • src/core/experiments/list.ts
  • src/core/segments/segments.ts
  • src/core/teams/get.ts
  • src/lib/utils/list-command.ts

Comment on lines 141 to 143
const rows = (users as Array<Record<string, unknown>>).map((u) =>
applyShowExclude(summarizeUserRow(u), u, show, exclude)
applyShowExclude(summarizeUserRow(u), u, show, exclude, showOnly)
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avatar lookup breaks when --show-only omits id.

On Line 172, avatar rendering keys off rows[dataIdx].id, but Line 142 now allows rows without id via showOnly, so avatars silently disappear for valid combinations like users list --show-avatars --show-only name. Use the source user array (stable identity) for avatar lookup instead of filtered row data.

💡 Proposed fix
-        if (/^│/.test(stripped) && dataIdx >= 0 && dataIdx < rows.length) {
-          const img = avatarMap.get(rows[dataIdx]!.id as number);
+        if (/^│/.test(stripped) && dataIdx >= 0 && dataIdx < rows.length) {
+          const sourceUserId = (users as User[])[dataIdx]!.id;
+          const img = avatarMap.get(sourceUserId);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/users/index.ts` around lines 141 - 143, The avatar rendering
breaks because summarizeUserRow/applyShowExclude may drop the id when showOnly
is used; change the avatar lookup to use the original source user identity
rather than the filtered row: when mapping users (the users array passed into
summarizeUserRow and applyShowExclude) either attach the original id (e.g., a
hidden __origId) to each produced row or, better, keep and use the original
users array for avatar lookup (use users[dataIdx].id) when rendering avatars
instead of rows[dataIdx].id; update any code that currently references
rows[dataIdx].id (avatar rendering code) to read the id from the preserved
source (users) or the added __origId so avatars remain stable even when showOnly
omits id.

@joalves joalves added this pull request to the merge queue May 25, 2026
Merged via the queue into main with commit 5556a9d May 25, 2026
5 checks passed
@joalves joalves deleted the feat/show-only-and-audience-json branch May 26, 2026 09:23
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.

1 participant