Skip to content

--top <n> flag to cap table rows - #40

Open
dchaudhari7177 wants to merge 1 commit into
notsointresting:mainfrom
dchaudhari7177:feat/top-flag
Open

--top <n> flag to cap table rows#40
dchaudhari7177 wants to merge 1 commit into
notsointresting:mainfrom
dchaudhari7177:feat/top-flag

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

report/skills/agents/cost printed every row. --top <n> caps them.

Behaviour

  • Caps after the sort, so it keeps the highest-ranked rows under whatever --sort is active (--sort name --top 3 gives the first three alphabetically, not the top three by fires).
  • Unlimited when omitted — current behaviour is untouched.
  • n is validated as a positive integer, following the existing --sort validation pattern: --top 0, --top 2.5, --top ten and --top=-3 all exit 2 with --top expects a positive integer.

Consistency across formats

Rather than capping inside each of the four renderers (easy to let one drift), the cap is applied to the Report itself — used/untracked/dead are sliced in one capReport helper that every format then renders. Terminal, json, md and csv therefore cap identically by construction. The --dead and --untracked row paths are capped too.

Applied to cost as well as report/skills/agents, since it is the same kind of component table and the flag surface is shared — happy to drop that if you'd rather keep it off cost.

Tests

New test/top.test.ts drives a synthetic four-row Report (same approach as sort.test.ts, since the fixture history only has one component so a cap can't be observed there): caps post-sort, caps after rather than before sorting, defaults to unlimited, is a no-op when n exceeds the row count, caps identically in all four formats, and applies to report. Flag validation is covered in test/cli.test.ts.

Typecheck and the full suite (89 passing) are green.

Closes #31

@notsointresting

Copy link
Copy Markdown
Owner

Conflict against main now — a few other PRs touching src/cli.ts/themes/index.ts landed first. Could you rebase onto main and resolve? Should just be re-applying your change alongside the others already merged.

report/skills/agents/cost printed every row, which is long on a machine with
hundreds of installed components. --top caps rows AFTER sorting, so it keeps the
highest-ranked under whatever --sort is active.

The cap is applied to the Report itself (used/untracked/dead) rather than in
each renderer, so terminal, json, md and csv cap identically by construction.
Omitting the flag is unlimited, preserving current behaviour. n is validated as
a positive integer, matching the --sort validation pattern.

Closes notsointresting#31
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.

--top <n> flag to cap table rows

3 participants