Skip to content

feat(command): add opt-in pagination via CommandSpec::with_pagination - #81

Merged
jpage-godaddy merged 2 commits into
mainfrom
opt-in-pagination
Aug 4, 2026
Merged

jpage-godaddy merged 2 commits into
mainfrom
opt-in-pagination

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • --limit/--offset were framework-global — registered for every command regardless of whether it does anything with them, pure opt-in via flags with no command-declared default, and silently a no-op on an object-shaped output envelope (only a bare top-level JSON array gets sliced).
  • Adds CommandSpec::with_pagination(PaginationConfig { default_limit, max_limit, ..Default::default() }): --limit/--offset are now registered (and shown in --help) only for a command that opts in. default_limit (0 = unlimited) applies when the user passes neither flag. max_limit (0 = uncapped) rejects an explicit --limit above the cap at parse time. --offset rejects a negative value at parse time too (a clap usage error), rather than only failing once the command has otherwise fully run.
  • GlobalFlags/Middleware no longer carry limit/offset as framework-global state; a command's own --limit/--offset are read off its leaf ArgMatches and applied per-invocation.

Resolves DEVEX-972.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets -- -D warnings
  • RUSTDOCFLAGS='-D warnings' cargo doc --no-deps / cargo rustdoc --lib -- -W missing-docs (0 missing)
  • cargo test --all-targets and cargo test --doc, including cargo test --release (the with_pagination misconfiguration check is a debug_assert!, compiled out under --release — the regression test accounts for that)
  • tests/pagination.rs: flag gating (absent/unknown-arg for non-opted-in commands), --help visibility, default_limit behavior, explicit override + pagination metadata, max_limit capping (incl. legacy negative-limit-means-unlimited), negative---offset rejection, and the default_limit > max_limit misconfiguration panic
  • Proved out end-to-end against a real consumer CLI (GoDaddy's gddy) via a local [patch.crates-io] override: wired .with_pagination(...) onto 4 real list commands, verified --help gating, pagination metadata, and max_limit rejection against the built binary

🤖 Generated with Claude Code

--limit/--offset were framework-global (registered for every command,
0=all, pure opt-in via flags) and silently no-op on object-shaped
envelopes. A command now declares PaginationConfig { default_limit,
max_limit } via .with_pagination(...) to register the flags for
itself only, apply a default page size when neither flag is passed,
and cap an explicit --limit.

DEVEX-972

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR changes pagination from framework-global behavior to an opt-in, per-command feature via CommandSpec::with_pagination(PaginationConfig { .. }), so --limit/--offset only exist (and appear in --help) for commands that explicitly declare pagination.

Changes:

  • Introduces PaginationConfig and CommandSpec::with_pagination(...) to declare per-command pagination defaults and caps.
  • Removes limit/offset from framework-global flags and wires pagination parsing/registration through per-command clap Command construction.
  • Adds/updates docs and adds end-to-end tests covering flag gating, defaults, metadata, and max-limit enforcement.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cli-engine/tests/pagination.rs New end-to-end tests for opt-in pagination behavior, help gating, defaults, metadata, and max_limit.
cli-engine/tests/foundation.rs Updates existing runtime tests to opt-in to pagination where needed; removes global flag expectations.
cli-engine/tests/exhaustive_public_api.rs Removes --limit/--offset from global-flags parsing expectations.
cli-engine/tests/exhaustive_cli_contract.rs Updates global flag validation tests now that numeric pagination flags are no longer global.
cli-engine/src/lib.rs Re-exports PaginationConfig as part of the public API surface.
cli-engine/src/flags.rs Removes global registration for --limit/--offset; adds per-command pagination arg registration helpers and parsing constraints for --limit.
cli-engine/src/command.rs Adds CommandSpec.pagination and the PaginationConfig type; introduces CommandSpec::with_pagination.
cli-engine/src/cli.rs Applies pagination values from leaf matches into middleware per invocation; registers pagination args only for opted-in commands.
cli-engine/docs/design.md Updates global flag documentation to reflect pagination opt-in behavior.
cli-engine/docs/concepts.md Updates concepts docs with the opt-in pagination explanation and example.
AGENTS.md Updates command authoring checklist to document the new opt-in pagination pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cli-engine/src/flags.rs Resolved
Comment thread cli-engine/tests/pagination.rs Resolved
Comment thread cli-engine/docs/design.md Resolved
…mode test

- --offset now uses a dedicated value parser that rejects negative
  values as a clap usage error, instead of letting them reach the
  output pipeline's runtime rejection.
- with_pagination's misconfiguration check is a debug_assert, compiled
  out under --release; gate the regression test's #[should_panic] on
  debug_assertions so it doesn't fail there.
- Fix a doc paragraph in design.md that got mangled mid-edit.

Addresses GitHub Copilot review feedback on #81.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Suppressed comments (2)

cli-engine/src/cli.rs:2564

  • PaginationConfig::default_limit is documented (and described in the PR) as applying only when the user passes neither --limit nor --offset, but this implementation will also apply it when the user passes --offset without --limit (because --limit is registered with a clap default value). That makes my-cli list --offset 10 unexpectedly cap results to default_limit instead of returning the full tail.
    middleware.limit = leaf
        .get_one::<i64>("limit")
        .copied()
        .unwrap_or(pagination.default_limit);
    middleware.offset = leaf.get_one::<i64>("offset").copied().unwrap_or(0);

cli-engine/src/flags.rs:343

  • The --limit help text says 0=all, but the parser and output pipeline also treat negative limits as "unlimited" (legacy behavior, covered by tests). Also, once default_limit is intended to apply only when neither --limit nor --offset is explicitly passed, the help string should reflect that conditional default to avoid misleading users.
fn pagination_limit_help(default_limit: i64, max_limit: i64) -> String {
    let mut help = format!("Max items to return (client-side, 0=all, default {default_limit}");
    if max_limit > 0 {
        help.push_str(&format!(", max {max_limit}"));
    }

@jpage-godaddy
jpage-godaddy merged commit d829f90 into main Aug 4, 2026
4 checks passed
@jpage-godaddy
jpage-godaddy deleted the opt-in-pagination branch August 4, 2026 17:09
@github-actions github-actions Bot mentioned this pull request Aug 4, 2026
jpage-godaddy pushed a commit that referenced this pull request Aug 4, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>cli-engine: 0.7.0</summary>

##
[0.7.0](cli-engine-v0.6.1...cli-engine-v0.7.0)
(2026-08-04)


### ⚠ BREAKING CHANGES

* **auth:** surface refresh-token availability on Credential/auth status
([#79](#79))

### Features

* **auth:** surface refresh-token availability on Credential/auth status
([#79](#79))
([d88d30c](d88d30c))
* **command:** add opt-in pagination via CommandSpec::with_pagination
([#81](#81))
([d829f90](d829f90))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants