From ab69ef2db44b6c4b7f00283d52d38fbe71d16c42 Mon Sep 17 00:00:00 2001 From: Devin J. Pohly Date: Sun, 2 Apr 2023 06:10:40 -0500 Subject: Count occurrences of flags (was "Add .count type for flags") (#96) Breaking change: parseEx now counts the number of occurrences of flag parameters (those with takes_value == .none) and returns the count as a u8. Users of the library will need to change if (arg_result.my_flag) to if (arg_result.my_flag != 0) --- example/README.md.template | 1 + example/help.zig | 2 +- example/simple-ex.zig | 2 +- example/simple.zig | 2 +- example/usage.zig | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) (limited to 'example') diff --git a/example/README.md.template b/example/README.md.template index 696c598..34bff56 100644 --- a/example/README.md.template +++ b/example/README.md.template @@ -14,6 +14,7 @@ in the release notes. * Short arguments `-a` * Chaining `-abc` where `a` and `b` does not take values. + * Multiple specifications are tallied (e.g. `-v -v`). * Long arguments `--long` * Supports both passing values using spacing and `=` (`-a 100`, `-a=100`) * Short args also support passing values with no spacing or `=` (`-a100`) diff --git a/example/help.zig b/example/help.zig index dd9c9ea..e83ae44 100644 --- a/example/help.zig +++ b/example/help.zig @@ -15,6 +15,6 @@ pub fn main() !void { // where `Id` has a `describtion` and `value` method (`Param(Help)` is one such parameter). // The last argument contains options as to how `help` should print those parameters. Using // `.{}` means the default options. - if (res.args.help) + if (res.args.help != 0) return clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{}); } diff --git a/example/simple-ex.zig b/example/simple-ex.zig index fb20d07..dd5d929 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig @@ -36,7 +36,7 @@ pub fn main() !void { }; defer res.deinit(); - if (res.args.help) + if (res.args.help != 0) debug.print("--help\n", .{}); if (res.args.number) |n| debug.print("--number = {}\n", .{n}); diff --git a/example/simple.zig b/example/simple.zig index 2d32463..429f095 100644 --- a/example/simple.zig +++ b/example/simple.zig @@ -28,7 +28,7 @@ pub fn main() !void { }; defer res.deinit(); - if (res.args.help) + if (res.args.help != 0) debug.print("--help\n", .{}); if (res.args.number) |n| debug.print("--number = {}\n", .{n}); diff --git a/example/usage.zig b/example/usage.zig index 0d21352..333536b 100644 --- a/example/usage.zig +++ b/example/usage.zig @@ -14,6 +14,6 @@ pub fn main() !void { // `clap.usage` is a function that can print a simple help message. It can print any `Param` // where `Id` has a `value` method (`Param(Help)` is one such parameter). - if (res.args.help) + if (res.args.help != 0) return clap.usage(std.io.getStdErr().writer(), clap.Help, ¶ms); } -- cgit v1.2.3