From 86342bcd1fa1523bc02f730ea849e7953f7d35ad Mon Sep 17 00:00:00 2001 From: torque Date: Fri, 4 Aug 2023 00:12:26 -0700 Subject: [PATCH] help: print byte slice defaults as strings There are a couple of other places where []u8 is treated implicitly like a string, which isn't strictly correct. Ultimately, some kind of metasignal will be required to make this type truly unambiguous in interpretation. --- source/help.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/help.zig b/source/help.zig index 73badb4..f115af4 100644 --- a/source/help.zig +++ b/source/help.zig @@ -226,7 +226,7 @@ pub fn HelpBuilder(comptime command: anytype) type { defer pairs.deinit(); var just: usize = 0; - inline for (comptime help_info.arguments) |arg| { + inline for (comptime help_info.arguments) |arg| { if (comptime arg.description.len == 0) continue; const pair: AlignablePair = .{ @@ -471,7 +471,17 @@ pub fn opt_info(comptime command: anytype) CommandHelp { // TODO: this is only acceptable for some types. It behaves poorly on // enum-based choice types because it prints the whole type name rather // than just the tag name. Roll our own eventually. - writer.print("{any}", .{def}) catch @compileError("whoah"); + blk: { + switch (@typeInfo(@TypeOf(def))) { + .Pointer => |info| if (info.size == .Slice and info.child == u8) { + writer.print("{s}", .{def}) catch @compileError("no"); + break :blk; + }, + else => {}, + } + writer.print("{any}", .{def}) catch @compileError("whoah"); + } + last_option.default = buf.buffer; } }