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.
This commit is contained in:
parent
94441fdc76
commit
ef7d19db9b
2 changed files with 19 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue