diff --git a/src/main.zig b/src/main.zig index 1514d3a..29deab3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -413,32 +413,44 @@ pub fn main() !void { } try stdout.flush(); - if (result.devices.len > 0) { - const device = result.devices[0]; - - if (device.serial_id) |sid| { - try stdout.print("šŸ” Checking recirculation status for {?s}...\n", .{device.device_name}); - try stdout.flush(); - - var status = try getRecirculationStatus(allocator, auth.id_token, sid); - defer status.deinit(); - - try stdout.print("\n{f}", .{status}); - - const recirc_enabled = status.recirculation_enabled orelse false; - - if (recirc_enabled) { - try stdout.print("\nāœ“ Recirculation is already active\n", .{}); - // Recirculation code commented out as requested - } else { - // 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", .{}); + switch (result.devices.len) { + 0 => { + try stderr.print("āŒ No devices found for user\n", .{}); try stderr.flush(); - return error.NoSerialId; - } + return error.NoDevicesFound; + }, + 1 => { + const device = result.devices[0]; + + if (device.serial_id) |sid| { + try stdout.print("šŸ” Checking recirculation status for {?s}...\n", .{device.device_name}); + try stdout.flush(); + + var status = try getRecirculationStatus(allocator, auth.id_token, sid); + defer status.deinit(); + + try stdout.print("\n{f}", .{status}); + + const recirc_enabled = status.recirculation_enabled orelse false; + + if (recirc_enabled) { + try stdout.print("\nāœ“ Recirculation is already active\n", .{}); + // Recirculation code commented out as requested + } else { + // 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; + } + }, + else => { + try stderr.print("āŒ More than one device found for user, not currently equipped to handle this\n", .{}); + try stderr.flush(); + return error.TooManyDevicesFound; + }, } }