Minor improvements

Let's not mark toggles as required... they shouldn't be.
This commit is contained in:
Lyssieth 2024-11-28 18:12:06 +02:00
parent 1617926615
commit 5eae72b4c1
Signed by untrusted user who does not match committer: lyssieth
GPG key ID: 200268854934CFAB

View file

@ -151,13 +151,15 @@ pub fn printHelp(comptime T: type, comptime name: []const u8, writer: std.io.Any
try writer.print(")", .{}); try writer.print(")", .{});
} }
if (flag.takesValue) {
try writer.print(": {s}", .{valueType}); try writer.print(": {s}", .{valueType});
if (flag.typeHint) |typeHint| { if (flag.typeHint) |typeHint| {
try writer.print(" ({s})", .{typeHint}); try writer.print(" ({s})", .{typeHint});
} }
}
if (!isOptional) { if (!isOptional and !flag.toggle) {
try writer.print(" <required>", .{}); try writer.print(" <required>", .{});
} }
@ -199,7 +201,7 @@ test "basic help" {
.Flag = .{ .Flag = .{
.name = "verbose", .name = "verbose",
.short = "v", .short = "v",
.takesValue = false,
.toggle = true, .toggle = true,
}, },
}, },
@ -221,7 +223,7 @@ test "basic help" {
\\Usage: demo [flags] <positional> [...] \\Usage: demo [flags] <positional> [...]
\\Legend: <required> [optional] \\Legend: <required> [optional]
\\ \\
\\* --verbose (-v): bool <required> \\* --verbose (-v)
\\* <positional>: string \\* <positional>: string
\\ \\
, buf.items); , buf.items);