Skip to content

Sub-commands with no values will never match #23

@erri120

Description

@erri120

Given the following structure:

program foo bar
const matches = try app.parseProcess(); // works fine
const fooMatches = matches.subcommandMatches("foo"); // works fine
const barMatches = fooMatches.subcommandMatches("bar"); // fails

Although fooMatches.subcommand is non-null and .name is equal to bar, subcommandMatches still returns null because bar didn't have any arguments.

This is an issue with subcommandMatches, because it returns ?ArgMatches, even if foo has the bar sub-command, the method returns subcmd.matches which will be null if bar doesn't have any arguments or further sub-commands.

This behavior should be different. The easiest solution is to update this:

yazap/src/Parser.zig

Lines 444 to 446 in 55444b9

if (!takes_value) {
return MatchedSubCommand.init(subcmd.name, null);
}

If the sub-command doesn't take any value, arg_matches should be set to a non-null value instead of null. Probably some empty value.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions