Skip to content

Commit a559396

Browse files
authored
Merge pull request #79 from kernel/neil/kernel-1025-update-the-ci-prompt-for-cli-updates
updated prompt to handle pagination endpoint updates
2 parents cb6bef9 + 66644fb commit a559396

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

.github/workflows/update-cli-coverage.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ jobs:
224224
| SDK Method | SDK Param Type | SDK Param Fields |
225225
|------------|----------------|------------------|
226226
| client.Browsers.New | BrowserNewParams | Proxy, Profile, Viewport, Extensions, ... |
227-
| client.Browsers.List | BrowserListParams | Limit, Offset, IncludeDeleted, ... |
227+
| client.Browsers.List | BrowserListParams | Page, PerPage, IncludeDeleted, ... |
228228
| client.Deployments.New | DeploymentNewParams | AppName, Region, EnvVars, ... |
229229
| ... | ... | ... |
230230
@@ -239,7 +239,7 @@ jobs:
239239
| CLI Command | CLI Flags |
240240
|-------------|-----------|
241241
| kernel browser create | --proxy, --profile, --viewport, ... |
242-
| kernel browser list | --limit, --offset, ... |
242+
| kernel browser list | --page, --per-page, ... |
243243
| ... | ... |
244244
245245
## Step 5: Gap Analysis (CRITICAL - DO NOT SKIP)
@@ -317,6 +317,50 @@ jobs:
317317
- Handle errors appropriately
318318
- Match the style of existing commands
319319
320+
# CLI Pagination UX for Paginated List Endpoints
321+
When an SDK update introduces pagination on a list endpoint (e.g., the return type
322+
changes to \`*pagination.OffsetPagination[T]\` and the params gain \`Limit\`/\`Offset\`
323+
fields), do NOT naively expose \`--limit\` and \`--offset\` flags. Instead, follow the
324+
page-based UX pattern used by \`kernel app list\` (see cmd/app.go):
325+
326+
## Flags
327+
- Add \`--page\` (int, default 1): 1-based page number.
328+
- Add \`--per-page\` (int, default 20): items per page.
329+
- Do NOT add \`--limit\` or \`--offset\` flags. These are implementation details the
330+
user should not need to think about.
331+
- Keep any filter flags the endpoint supports (e.g., \`--query\`, \`--name\`, \`--status\`).
332+
333+
## Pagination Logic (the \"+1 trick\")
334+
The SDK's \`OffsetPagination\` struct stores response headers (\`X-Has-More\`,
335+
\`X-Next-Offset\`) in private fields that the CLI cannot access. To detect whether
336+
more pages exist without an extra API call, request one extra item:
337+
1. Set \`params.Limit = perPage + 1\`
338+
2. Set \`params.Offset = (page - 1) * perPage\`
339+
3. If the API returns more than \`perPage\` items, \`hasMore = true\`; truncate to
340+
\`perPage\` items for display.
341+
4. Otherwise \`hasMore = false\`.
342+
343+
## Pagination Footer
344+
After rendering the table, always print a pagination footer (using \`pterm.Printf\`
345+
so test output capture works):
346+
Page: 1 Per-page: 20 Items this page: 20 Has more: yes
347+
Next: kernel <resource> list --page 2 --per-page 20
348+
- The footer line is always printed (even when \`hasMore\` is false).
349+
- The \"Next:\" line is only printed when \`hasMore\` is true.
350+
- Preserve all filter flags in the \"Next:\" hint. Always quote string values
351+
(e.g., \`--query \"value\"\`) to handle multi-word values safely.
352+
- Use \`lo.Ternary(hasMore, \"yes\", \"no\")\` for the Has more value
353+
(import \`github.com/samber/lo\`, already a dependency).
354+
- Do NOT print the footer when \`--output json\` is used.
355+
356+
## Input Struct
357+
Use \`Page int\` and \`PerPage int\` in the list input struct, not \`Limit\`/\`Offset\`.
358+
Default both defensively in the List method body (\`page <= 0\` -> 1, \`perPage <= 0\` -> 20).
359+
360+
## Example Reference
361+
See \`cmd/profiles.go\` ProfilesCmd.List and \`cmd/app.go\` runAppList for working
362+
implementations of this pattern.
363+
320364
# Output Format
321365
After pushing changes, create or update an evergreen PR using gh:
322366

0 commit comments

Comments
 (0)