Skip to content

Commit

Permalink
feat(ParseResult): Add isEmpty API to check result emptyness
Browse files Browse the repository at this point in the history
Signed-off-by: prajwalch <[email protected]>
  • Loading branch information
prajwalch committed Sep 4, 2024
1 parent 51a1f93 commit a233417
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/ArgMatches.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ parse_result: *const ParseResult,
/// }
/// ```
pub fn containsArgs(self: *const ArgMatches) bool {
// zig fmt: off
return (self.parse_result.getArgs().count() >= 1
or self.parse_result.getSubcommandParseResult() != null);
// zig fmt: on
return !self.parse_result.isEmpty();
}

/// Checks whether an option, positional argument or subcommand with the
Expand Down
5 changes: 5 additions & 0 deletions src/parser/ParseResult.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ pub fn getSubcommandParseResult(self: *const ParseResult) ?*const ParseResult {
return @as(?*const ParseResult, self.subcmd_parse_result);
}

/// Returns `true` if the result is completely empty.
pub fn isEmpty(self: *const ParseResult) bool {
return (self.getArgs().count() == 0) and (self.getSubcommandParseResult() == null);
}

/// Inserts a given name-value pair into the map.
///
/// If the map already contains the name, value will be updated and if it didn't
Expand Down

0 comments on commit a233417

Please sign in to comment.