a73x

39627b18

refactor: cliflags owns the two words that ask about the binary

a73x   2026-08-28 19:53

Commit message
refactor: cliflags owns the two words that ask about the binary

`--help`/`-h` and `--version` were spelled inside parse's pre-scan only,
so a caller that must answer them before its own verb check had to spell
them again. isHelp/isVersion are that one place.

src/cli/flags.zig
Old New
@@ -57,8 +57,8 @@ pub fn parse(comptime T: type, dst: *T, args: []const [:0]const u8) Outcome {
57 // instead of the keystrokes would be the parser answering for the user. 57 // instead of the keystrokes would be the parser answering for the user.
58 for (args) |a| { 58 for (args) |a| {
59 if (std.mem.eql(u8, a, "--")) break; 59 if (std.mem.eql(u8, a, "--")) break;
60 if (std.mem.eql(u8, a, "--help") or std.mem.eql(u8, a, "-h")) return .help; 60 if (isHelp(a)) return .help;
61 if (std.mem.eql(u8, a, "--version")) return .version; 61 if (isVersion(a)) return .version;
62 } 62 }
63 63
64 var i: usize = 0; 64 var i: usize = 0;
@@ -125,6 +125,14 @@ fn aliasHit(comptime T: type, comptime field: []const u8, a: []const u8) bool {
125 return false; 125 return false;
126 } 126 }
127 127
128 pub fn isHelp(a: []const u8) bool {
129 return std.mem.eql(u8, a, "--help") or std.mem.eql(u8, a, "-h");
130 }
131
132 pub fn isVersion(a: []const u8) bool {
133 return std.mem.eql(u8, a, "--version");
134 }
135
128 pub fn help(usage: []const u8) u8 { 136 pub fn help(usage: []const u8) u8 {
129 // stdout, unlike every refusal: a usage someone ASKED for is output, 137 // stdout, unlike every refusal: a usage someone ASKED for is output,
130 // and they may well have piped it into a pager. version shares both 138 // and they may well have piped it into a pager. version shares both