this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add task show subcommand to display full details

bnjox 9ca5ef3c 81686a17

+109
+109
src/core/task.zig
··· 69 69 delete: struct { 70 70 id: []const u8, 71 71 }, 72 + show: struct { 73 + id: []const u8, 74 + }, 72 75 } = null, 73 76 74 77 pub const help = ··· 86 89 \\ --desc=<description> The description of the task 87 90 \\ delete 88 91 \\ --id=<id> delete task id. 92 + \\ show 93 + \\ --id=<id> Show task details 89 94 \\ 90 95 \\ 91 96 \\Examples: ··· 120 125 }, 121 126 .delete => |del| delete_task(allocator, del.id, dir) catch { 122 127 std.debug.print("Failed to delete task with id: {s}\n", .{del.id}); 128 + return; 129 + }, 130 + .show => |s| show_task(allocator, s.id, dir) catch { 131 + std.debug.print("Failed to show task with id: {s}\n", .{s.id}); 123 132 return; 124 133 }, 125 134 } ··· 323 332 324 333 try storage.save_tasks(arena_alloc, dir, remaining.items); 325 334 std.debug.print("Task deleted: {s}\n", .{tasks[found_indices.items[0]].title}); 335 + } 336 + 337 + /// Displays full details of a task by ID. Supports partial ID matching (min 4 chars). 338 + fn show_task(allocator: std.mem.Allocator, task_id: []const u8, dir: std.fs.Dir) !void { 339 + var arena = std.heap.ArenaAllocator.init(allocator); 340 + defer arena.deinit(); 341 + 342 + const arena_alloc = arena.allocator(); 343 + 344 + const tasks = storage.load_tasks(arena_alloc, dir) catch { 345 + return; 346 + }; 347 + 348 + var found_indices: std.ArrayList(usize) = .empty; 349 + defer found_indices.deinit(arena_alloc); 350 + 351 + for (tasks, 0..) |task, i| { 352 + const match = if (task_id.len >= 4 and task.id.len >= task_id.len) 353 + std.mem.eql(u8, task.id[0..task_id.len], task_id) 354 + else 355 + std.mem.eql(u8, task.id, task_id); 356 + 357 + if (match) { 358 + try found_indices.append(arena_alloc, i); 359 + } 360 + } 361 + 362 + if (found_indices.items.len == 0) { 363 + std.debug.print("No task found matching '{s}'\n", .{task_id}); 364 + return error.InvalidItem; 365 + } 366 + 367 + if (found_indices.items.len > 1) { 368 + std.debug.print("Multiple tasks match '{s}':\n", .{task_id}); 369 + for (found_indices.items) |idx| { 370 + const task = tasks[idx]; 371 + std.debug.print(" - {s} [{s}]\n", .{ task.id[0..@min(8, task.id.len)], task.title }); 372 + } 373 + std.debug.print("Use a longer ID to disambiguate.\n", .{}); 374 + return error.AmbiguousMatch; 375 + } 376 + 377 + const task = tasks[found_indices.items[0]]; 378 + try print_task_full_details(task); 379 + } 380 + 381 + fn print_task_full_details(task: models.Task) !void { 382 + const c_status = status_color(task.status); 383 + const c_reset = color(.reset); 384 + 385 + std.debug.print("{s}=== Task Details ==={s}\n\n", .{ color(.cyan), c_reset }); 386 + 387 + std.debug.print("ID: {s}\n", .{task.id}); 388 + std.debug.print("Title: {s}\n", .{task.title}); 389 + 390 + if (task.description) |desc| { 391 + std.debug.print("Description: {s}\n", .{desc}); 392 + } else { 393 + std.debug.print("Description: -\n", .{}); 394 + } 395 + 396 + std.debug.print("Status: {s}{s}{s}\n", .{ color(c_status), status_icon(task.status), c_reset }); 397 + 398 + if (task.priority) |p| { 399 + std.debug.print("Priority: {s}{s}{s}\n", .{ color(priority_color(task.priority)), priority_label(p), c_reset }); 400 + } else { 401 + std.debug.print("Priority: -\n", .{}); 402 + } 403 + 404 + if (task.due_date) |due| { 405 + const now = std.time.timestamp(); 406 + if (due < now) { 407 + std.debug.print("Due Date: {d} (overdue)\n", .{due}); 408 + } else { 409 + std.debug.print("Due Date: {d}\n", .{due}); 410 + } 411 + } else { 412 + std.debug.print("Due Date: -\n", .{}); 413 + } 414 + 415 + if (task.assigned_to) |assigned| { 416 + std.debug.print("Assigned To: {s}\n", .{assigned}); 417 + } else { 418 + std.debug.print("Assigned To: -\n", .{}); 419 + } 420 + 421 + std.debug.print("\n", .{}); 422 + std.debug.print("Created: {d}\n", .{task.created_at}); 423 + 424 + if (task.updated_at) |updated| { 425 + std.debug.print("Updated: {d}\n", .{updated}); 426 + } else { 427 + std.debug.print("Updated: -\n", .{}); 428 + } 429 + 430 + if (task.completed_at) |completed| { 431 + std.debug.print("Completed: {d}\n", .{completed}); 432 + } else { 433 + std.debug.print("Completed: -\n", .{}); 434 + } 326 435 } 327 436 328 437 test "add and list tasks" {