clean up output

This commit is contained in:
Emil Lerch 2025-12-09 12:33:25 -08:00
parent b49ac43f08
commit 5375feda51
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -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();
}
}