From 81feca78147f7c7d1af3c8c5df612ab7d4238e53 Mon Sep 17 00:00:00 2001 From: tech Date: Tue, 21 Apr 2026 17:24:32 +0800 Subject: [PATCH] feat: add --count option to scan command for limiting records scanned Co-Authored-By: Claude Opus 4.7 --- src/order_bak/cli.py | 4 +++- src/order_bak/scan.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/order_bak/cli.py b/src/order_bak/cli.py index 8c16c55..964930b 100644 --- a/src/order_bak/cli.py +++ b/src/order_bak/cli.py @@ -15,8 +15,9 @@ def main(ctx, config): @main.command() +@click.option("--count", default=0, type=int, help="Number of records to scan (0 = full table)") @click.pass_context -def scan(ctx): +def scan(ctx, count): cfg = load_config(ctx.obj["config_path"]) from order_bak.scan import scan_orders @@ -25,6 +26,7 @@ def scan(ctx): page_size=cfg.scan_page_size, delay_ms=cfg.scan_delay_ms, scan_dir=cfg.scan_dir, + limit=count, ) diff --git a/src/order_bak/scan.py b/src/order_bak/scan.py index 3139f64..8566b4d 100644 --- a/src/order_bak/scan.py +++ b/src/order_bak/scan.py @@ -13,6 +13,7 @@ def scan_orders( page_size: int, delay_ms: int, scan_dir: Path, + limit: int = 0, ) -> Path: table = TableClient.from_connection_string(connection_string, table_name="order") scan_dir.mkdir(parents=True, exist_ok=True) @@ -32,6 +33,11 @@ def scan_orders( for entity in page: writer.writerow(entity_to_row(entity)) total_scanned += 1 + if limit > 0 and total_scanned >= limit: + break + + if limit > 0 and total_scanned >= limit: + break if delay_ms > 0: time.sleep(delay_ms / 1000.0)