From 5375feda51fe8367a80dac24f3a4d9461c6e3869 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 9 Dec 2025 12:33:25 -0800 Subject: [PATCH] clean up output --- src/main.zig | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index d4942f7..6dd5315 100644 --- a/src/main.zig +++ b/src/main.zig @@ -251,12 +251,13 @@ pub fn main() !void { defer creds.deinit(); try stdout.print("🔐 Authenticating...\n", .{}); + try stdout.flush(); const auth = try authenticate(allocator, creds.username, creds.password); defer allocator.free(auth.id_token); defer allocator.free(auth.user_uuid); try stdout.print("✓ User UUID: {s}\n\n", .{auth.user_uuid}); - try stdout.print("📱 Fetching devices...\n", .{}); + try stdout.flush(); const result = try getDevices(allocator, auth.id_token, creds.username); defer result.deinit(); @@ -285,6 +286,7 @@ pub fn main() !void { try stdout.print(" Serial ID: {s}\n", .{serial_id}); try stdout.print(" Model: {s}\n\n", .{model}); } + try stdout.flush(); if (devices.array.items.len > 0) { const device = devices.array.items[0]; @@ -297,6 +299,7 @@ pub fn main() !void { if (serial_id) |sid| { const device_name = if (device.object.get("device_name")) |n| if (n == .string) n.string else "Unnamed" else "Unnamed"; try stdout.print("🔍 Checking recirculation status for {s}...\n", .{device_name}); + try stdout.flush(); const status = try getRecirculationStatus(allocator, auth.id_token, sid); defer status.deinit(); @@ -333,10 +336,12 @@ pub fn main() !void { // Recirculation code would go here but not called during testing try stdout.print("\n(Recirculation start function available but not called during testing)\n", .{}); } + try stdout.flush(); } } } else { try stderr.print("❌ No serial_id found for device\n", .{}); + try stderr.flush(); return error.NoSerialId; } } @@ -346,8 +351,9 @@ pub fn main() !void { } } } else { - const err_str = try std.fmt.allocPrint(allocator, "{}", .{result.value}); - defer allocator.free(err_str); - try stderr.print("❌ Error: {s}\n", .{err_str}); + try stderr.writeAll("❌ Error fetching devices. Response: "); + try std.json.Stringify.value(result.value, .{}, stderr); + + try stderr.flush(); } }