From 3619af2d4c0532aaddabbbbbd2810762e7a73f21 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Mon, 20 Apr 2026 14:49:21 +0300 Subject: [PATCH] `cli`: reintroduce old `--help` --- src/cli.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cli.zig b/src/cli.zig index 72b5b579..fcfb3aef 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -269,6 +269,13 @@ pub fn Builder(comptime commands: anytype) type { // Last resort, try sniffing. const command_enum = try sniffCommand(cmd_str); + + // `help` takes no arguments; short-circuit so the sniffed flag + // isn't re-parsed as an unknown option. + if (command_enum == .help) { + return .{ exec_name, .{ .help = .{} } }; + } + // "cmd_str" wasn't a command but an option. We can't reset args, but // we can create a new one. Not great, but this fallback is temporary // as we transition to this command mode approach. @@ -318,6 +325,11 @@ pub fn Builder(comptime commands: anytype) type { } } + // Legacy `--help` flag maps to the `help` command. + if (std.mem.eql(u8, cmd_str, "--help")) { + return .help; + } + return error.UnknownCommand; }