Repository navigation
feat(command): add opt-in pagination via CommandSpec::with_pagination - #81
Merged
Merged
Conversation
--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>
There was a problem hiding this comment.
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
PaginationConfigandCommandSpec::with_pagination(...)to declare per-command pagination defaults and caps. - Removes
limit/offsetfrom framework-global flags and wires pagination parsing/registration through per-command clapCommandconstruction. - 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.
…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>
There was a problem hiding this comment.
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_limitis documented (and described in the PR) as applying only when the user passes neither--limitnor--offset, but this implementation will also apply it when the user passes--offsetwithout--limit(because--limitis registered with a clap default value). That makesmy-cli list --offset 10unexpectedly cap results todefault_limitinstead 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
--limithelp text says0=all, but the parser and output pipeline also treat negative limits as "unlimited" (legacy behavior, covered by tests). Also, oncedefault_limitis intended to apply only when neither--limitnor--offsetis 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}"));
}
qcai-godaddy
approved these changes
Aug 4, 2026
Merged
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--limit/--offsetwere 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).CommandSpec::with_pagination(PaginationConfig { default_limit, max_limit, ..Default::default() }):--limit/--offsetare 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--limitabove the cap at parse time.--offsetrejects a negative value at parse time too (aclapusage error), rather than only failing once the command has otherwise fully run.GlobalFlags/Middlewareno longer carrylimit/offsetas framework-global state; a command's own--limit/--offsetare read off its leafArgMatchesand applied per-invocation.Resolves DEVEX-972.
Test plan
cargo fmt --all --checkcargo clippy --all-targets -- -D warningsRUSTDOCFLAGS='-D warnings' cargo doc --no-deps/cargo rustdoc --lib -- -W missing-docs(0 missing)cargo test --all-targetsandcargo test --doc, includingcargo test --release(thewith_paginationmisconfiguration check is adebug_assert!, compiled out under--release— the regression test accounts for that)tests/pagination.rs: flag gating (absent/unknown-arg for non-opted-in commands),--helpvisibility,default_limitbehavior, explicit override + pagination metadata,max_limitcapping (incl. legacy negative-limit-means-unlimited), negative---offsetrejection, and thedefault_limit > max_limitmisconfiguration panicgddy) via a local[patch.crates-io]override: wired.with_pagination(...)onto 4 real list commands, verified--helpgating, pagination metadata, andmax_limitrejection against the built binary🤖 Generated with Claude Code