diff --git a/src/order_bak/cli.py b/src/order_bak/cli.py index 73ee1bf..658ff57 100644 --- a/src/order_bak/cli.py +++ b/src/order_bak/cli.py @@ -74,24 +74,27 @@ def delete(ctx): if not backup_files: click.echo("No backup files found in ./backups") raise SystemExit(1) - csv_file = backup_files[-1] import csv as csv_mod - with open(csv_file, newline="") as f: - count = sum(1 for _ in csv_mod.DictReader(f)) + total = 0 + for f in backup_files: + with open(f, newline="") as fh: + total += sum(1 for _ in csv_mod.DictReader(fh)) + click.echo(f" {f}") - click.echo(f"Will delete {count} orders from {csv_file}") + click.echo(f"Will delete {total} orders from {len(backup_files)} file(s)") if not click.confirm("Continue?"): click.echo("Aborted") return table = TableClient.from_connection_string(cfg.azure_connection_string, table_name="order") - delete_orders( - table_client=table, - csv_path=csv_file, - batch_size=cfg.delete_batch_size, - delay_ms=cfg.delete_delay_ms, - ) + for csv_file in backup_files: + delete_orders( + table_client=table, + csv_path=csv_file, + batch_size=cfg.delete_batch_size, + delay_ms=cfg.delete_delay_ms, + ) if __name__ == "__main__":