-
Notifications
You must be signed in to change notification settings - Fork 3
eops-378(fix): Fix using --all display a warning letting the user know there are more records if we hit the limit #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| import typer | ||||||
|
|
||||||
| from dualentry_cli.cli import HelpfulGroup | ||||||
| from dualentry_cli.client import _MAX_PAGES | ||||||
| from dualentry_cli.output import _RECORD_PREFIX, format_output | ||||||
|
|
||||||
| # ── Shared option defaults ────────────────────────────────────────── | ||||||
|
|
@@ -72,15 +73,58 @@ def _build_filter_params( | |||||
| return params | ||||||
|
|
||||||
|
|
||||||
| # Map _do_list filter kwargs to CLI flags for the --all resume hint. | ||||||
| _FILTER_CLI_FLAGS = { | ||||||
| "search": "--search", | ||||||
| "status": "--status", | ||||||
| "start_date": "--start-date", | ||||||
| "end_date": "--end-date", | ||||||
| "company_id": "--company", | ||||||
| "customer_id": "--customer", | ||||||
| "vendor_id": "--vendor", | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| def _resume_all_command(path: str, next_offset: int, filters: dict) -> str: | ||||||
| """Build a copy-paste dualentry list --all command that continues from next_offset.""" | ||||||
| parts = ["dualentry", *path.split("/"), "list", "--all", "--offset", str(next_offset)] | ||||||
| for key, flag in _FILTER_CLI_FLAGS.items(): | ||||||
| value = filters.get(key) | ||||||
| if value is not None: | ||||||
| parts.extend([flag, str(value)]) | ||||||
| return " ".join(parts) | ||||||
|
|
||||||
|
|
||||||
| def _warn_all_truncated(path: str, *, fetched_through: int, total: int, next_offset: int, filters: dict) -> None: | ||||||
| """Tell the user --all stopped early and how to continue.""" | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Command: tighten the filter check at
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale — resume hint already uses |
||||||
| cmd = _resume_all_command(path, next_offset, filters) | ||||||
| typer.secho( | ||||||
| f"Warning: reached {fetched_through} of {total} items; stopped at the {_MAX_PAGES}-page limit.\nTo continue, re-run with the same filters:\n {cmd}", | ||||||
| fg=typer.colors.YELLOW, | ||||||
| err=True, | ||||||
| ) | ||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Command: move the import to the top of
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale — |
||||||
|
|
||||||
| def _do_list(client, path: str, resource: str, *, limit: int, offset: int, all_pages: bool, output: str, **filters): | ||||||
| """Shared list logic for all resources.""" | ||||||
| params = _build_filter_params(**filters) | ||||||
| next_offset = None | ||||||
| if all_pages: | ||||||
| data = client.paginate(f"/{path}/", params=params) | ||||||
| data = client.paginate(f"/{path}/", params=params, start_offset=offset) | ||||||
| next_offset = data.pop("next_offset", None) | ||||||
| else: | ||||||
| params.update({"limit": limit, "offset": offset}) | ||||||
| data = client.get(f"/{path}/", params=params) | ||||||
| format_output(data, resource=resource, fmt=output) | ||||||
| # After the table so the resume hint is visible without scrolling up. | ||||||
| if next_offset is not None: | ||||||
| _warn_all_truncated( | ||||||
| path, | ||||||
| fetched_through=next_offset, | ||||||
| total=data.get("count", next_offset), | ||||||
| next_offset=next_offset, | ||||||
| filters=filters, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def _load_json_file(file: Path) -> dict: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_FILTER_CLI_FLAGSstores filter-to-flag mappings as a positional tuple, which is error-prone and O(N) on every resume command. Siblings use a dict for this pattern.Command: convert
_FILTER_CLI_FLAGSto a dict atcommands/__init__.py:75.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale —
_FILTER_CLI_FLAGSis already a dict (317c799).