From a233417857bf2c9bab8adca9f1206c3482f42af7 Mon Sep 17 00:00:00 2001 From: prajwalch Date: Wed, 4 Sep 2024 18:40:42 +0545 Subject: [PATCH] feat(ParseResult): Add `isEmpty` API to check result emptyness Signed-off-by: prajwalch --- src/ArgMatches.zig | 5 +---- src/parser/ParseResult.zig | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ArgMatches.zig b/src/ArgMatches.zig index 4975bb4..8ded940 100644 --- a/src/ArgMatches.zig +++ b/src/ArgMatches.zig @@ -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 diff --git a/src/parser/ParseResult.zig b/src/parser/ParseResult.zig index 236f827..1120b37 100644 --- a/src/parser/ParseResult.zig +++ b/src/parser/ParseResult.zig @@ -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