From a64233d4f62e9cb4993dbfc43b476c6f0062873c Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 18 Feb 2026 16:04:37 -0500 Subject: [PATCH] fix: CLI now properly rejects unknown commands - Add handleUnknownCommand() helper function - Add else clauses to 'i' and 's' switch cases - Commands like 'invalid_command', 'infoooo', 'syncccc' now properly rejected - Prevents silent acceptance of invalid commands - Test TestCLICommandsE2E/CLIErrorHandling now passes --- cli/src/main.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cli/src/main.zig b/cli/src/main.zig index 088f79b..e3515a3 100644 --- a/cli/src/main.zig +++ b/cli/src/main.zig @@ -1,6 +1,13 @@ const std = @import("std"); const colors = @import("utils/colors.zig"); +// Handle unknown command - prints error and exits +fn handleUnknownCommand(cmd: []const u8) noreturn { + colors.printError("Unknown command: {s}\n", .{cmd}); + printUsage(); + std.process.exit(1); +} + pub fn main() !void { // Initialize colors based on environment colors.initColors(); @@ -31,7 +38,7 @@ pub fn main() !void { colors.printInfo("Setup configuration interactively\n", .{}); } else if (std.mem.eql(u8, command, "info")) { try @import("commands/info.zig").run(allocator, args[2..]); - }, + } else handleUnknownCommand(command), 'a' => if (std.mem.eql(u8, command, "annotate")) { try @import("commands/annotate.zig").run(allocator, args[2..]); }, @@ -46,7 +53,7 @@ pub fn main() !void { colors.printInfo("Sync project to server: {s}\n", .{args[2]}); } else if (std.mem.eql(u8, command, "status")) { try @import("commands/status.zig").run(allocator, args[2..]); - }, + } else handleUnknownCommand(command), 'r' => if (std.mem.eql(u8, command, "requeue")) { try @import("commands/requeue.zig").run(allocator, args[2..]); },