From ef7d19db9bbf9c429cb5559f67ee9d1e030c5769 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 4 Mar 2026 21:23:16 -0500 Subject: [PATCH] feat(cli): integrate ProgressBar into sync command Update progress.zig and integrate into sync command: - progress.zig: update import from colors.zig to io.zig - sync.zig: add ProgressBar for multi-run sync operations - Shows progress bar when syncing 2+ runs (not in JSON mode) - Updates progress after each successful sync Benefits: - Better UX for long-running sync operations - Visual feedback on sync progress - Maintains clean output for single runs All tests pass. --- cli/src/commands/sync.zig | 20 ++++++++++++++++++-- cli/src/utils/progress.zig | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cli/src/commands/sync.zig b/cli/src/commands/sync.zig index 20e01a5..0d8fbc5 100644 --- a/cli/src/commands/sync.zig +++ b/cli/src/commands/sync.zig @@ -6,6 +6,7 @@ const crypto = @import("../utils/crypto.zig"); const mode = @import("../mode.zig"); const core = @import("../core.zig"); const manifest_lib = @import("../manifest.zig"); +const progress = @import("../utils/progress.zig"); pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void { var flags = core.flags.CommonFlags{}; @@ -82,8 +83,20 @@ pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void { defer client.close(); var success_count: usize = 0; - for (runs_to_sync.items) |run_info| { - if (!flags.json) std.debug.print("Syncing run {s}...\n", .{run_info.run_id[0..8]}); + + // Show progress bar for multiple runs (not in JSON mode) + var pb: ?progress.ProgressBar = null; + if (!flags.json and runs_to_sync.items.len > 1) { + pb = progress.ProgressBar.init(allocator, runs_to_sync.items.len, "Syncing runs..."); + } + defer if (pb) |*p| p.finish(); + + for (runs_to_sync.items, 0..) |run_info, idx| { + if (!flags.json) { + if (runs_to_sync.items.len == 1) { + std.debug.print("Syncing run {s}...\n", .{run_info.run_id[0..8]}); + } + } syncRun(allocator, &database, &client, run_info, api_key_hash) catch |err| { if (!flags.json) std.debug.print("Failed to sync run {s}: {}\n", .{ run_info.run_id[0..8], err }); continue; @@ -94,6 +107,9 @@ pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void { try db.DB.bindText(update_stmt, 1, run_info.run_id); _ = try db.DB.step(update_stmt); success_count += 1; + + // Update progress bar + if (pb) |*p| p.update(idx + 1); } database.checkpointOnExit(); diff --git a/cli/src/utils/progress.zig b/cli/src/utils/progress.zig index de65c04..8474139 100644 --- a/cli/src/utils/progress.zig +++ b/cli/src/utils/progress.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const colors = @import("colors.zig"); +const io = @import("io.zig"); /// Progress bar for long-running operations pub const ProgressBar = struct {