summaryrefslogtreecommitdiff
path: root/src/cli/args.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-01-20 09:29:26 -0800
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-01-20 09:29:26 -0800
commitb438998fb82d07e7f29a71cec30e1f46a7a7a0fc (patch)
treeee31f31c74b0edad5daf1b7f60dfe737b8005261 /src/cli/args.zig
parent203b38fdac0b18d0e26418390dcaca914357c28c (diff)
cli: support --help and -h for actions
Diffstat (limited to 'src/cli/args.zig')
-rw-r--r--src/cli/args.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cli/args.zig b/src/cli/args.zig
index c226493f9..773457cf8 100644
--- a/src/cli/args.zig
+++ b/src/cli/args.zig
@@ -77,6 +77,17 @@ pub fn parse(comptime T: type, alloc: Allocator, dst: *T, iter: anytype) !void {
if (!try dst.parseManuallyHook(arena_alloc, arg, iter)) return;
}
+ // If the destination supports help then we check for it, call
+ // the help function and return.
+ if (@hasDecl(T, "help")) {
+ if (mem.eql(u8, arg, "--help") or
+ mem.eql(u8, arg, "-h"))
+ {
+ try dst.help();
+ return;
+ }
+ }
+
if (mem.startsWith(u8, arg, "--")) {
var key: []const u8 = arg[2..];
const value: ?[]const u8 = value: {