a73x

419bbe5f

fix: mux hosts --help and --version answer before the verb check, wherever they sit

a73x   2026-08-28 19:53

Commit message
fix: mux hosts --help and --version answer before the verb check, wherever they sit

src/cli/mux_main.zig
Old New
@@ -568,6 +568,14 @@ fn hostsMain(
568 const path = state_path orelse try hosts.statePath(arena); 568 const path = state_path orelse try hosts.statePath(arena);
569 569
570 if (args.len == 0) return hostsList(arena, path, std.posix.STDOUT_FILENO); 570 if (args.len == 0) return hostsList(arena, path, std.posix.STDOUT_FILENO);
571 // Before the verb check, and wherever it sits — the rule `cliflags.parse`
572 // already follows inside `add`. Asking what a command does is not
573 // mistyping its name, and "add or rm, not '--help'" sends the user
574 // looking for a subcommand they never meant.
575 for (args) |a| {
576 if (cliflags.isHelp(a)) return cliflags.help(usage);
577 if (cliflags.isVersion(a)) return cliflags.version("mux", build_options.version);
578 }
571 const adding = std.mem.eql(u8, args[0], "add"); 579 const adding = std.mem.eql(u8, args[0], "add");
572 if (!adding and !std.mem.eql(u8, args[0], "rm")) { 580 if (!adding and !std.mem.eql(u8, args[0], "rm")) {
573 std.debug.print("mux hosts: add or rm, not '{s}'\n{s}", .{ args[0], usage }); 581 std.debug.print("mux hosts: add or rm, not '{s}'\n{s}", .{ args[0], usage });
@@ -879,6 +887,10 @@ test "hosts: add refuses a session by name, rm reports an unlisted host, the fil
879 887
880 // Neither verb is a subcommand this program has. 888 // Neither verb is a subcommand this program has.
881 try std.testing.expectEqual(@as(u8, 2), try hostsMain(alloc, &[_][:0]const u8{"list"}, path)); 889 try std.testing.expectEqual(@as(u8, 2), try hostsMain(alloc, &[_][:0]const u8{"list"}, path));
890
891 // `mux hosts --help` is asserted in test/e2e_09_hosts.sh, not here: the
892 // answer is a page on fd 1, and a unit test that let it out would write
893 // over the test runner's own protocol stream.
882 } 894 }
883 895
884 test "hosts: a line the file cannot hold exits 2 wherever the file is read" { 896 test "hosts: a line the file cannot hold exits 2 wherever the file is read" {