prajwalch / yazap

🔧 The ultimate Zig library for seamless command line argument parsing.
https://prajwalch.github.io/yazap
MIT License
152 stars 13 forks source link

Subcommand help not working #27

Closed malaow3 closed 1 month ago

malaow3 commented 2 months ago

Following the examples in the readme, trying to print the subcommand help displays nothing.

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var app = App.init(allocator, "myapp", "My app description");
    defer app.deinit();

    var root = app.rootCommand();

    var subcmd = app.createCommand("subcmd", "Subcommand description");
    try subcmd.addArg(Arg.booleanOption("verbose", 'v', "Enable verbose output"));
    try root.addSubcommand(subcmd);

    const matches = try app.parseProcess();

    if (matches.subcommandMatches("subcmd")) |subcmd_matches| {
        if (!subcmd_matches.containsArgs()) {
            try app.displaySubcommandHelp();
            return;
        }
    }
}
./zig-out/bin/example subcmd
prajwalch commented 1 month ago

Hi, this is now fixed :)