parser: support requiring subcommands

This commit is contained in:
torque 2023-04-04 23:19:28 -07:00
parent 1e4a5828f8
commit ab07222666
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -141,6 +141,11 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
&[_][]const u8{ name, args[sliceto - 1] }, &[_][]const u8{ name, args[sliceto - 1] },
); );
try verb.parse(verbname, args[sliceto..], env); try verb.parse(verbname, args[sliceto..], env);
} else if (self.subcommands.count() > 0 and command.subcommand_required) {
const stderr = std.io.getStdErr().writer();
try stderr.writeAll("A subcommand is required.\n\n");
self.print_help(name);
} }
} }