From 58949127d6aa64abf4b4373a01c67779069b4421 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 29 Aug 2023 07:26:11 -0700 Subject: [PATCH] add help to demo program --- src/main.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.zig b/src/main.zig index 79a2de5..17d38cc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -63,7 +63,25 @@ pub fn main() anyerror!void { defer tests.deinit(); var args = try std.process.argsWithAllocator(allocator); defer args.deinit(); + const stdout_raw = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_raw); + defer bw.flush() catch unreachable; + const stdout = bw.writer(); + var arg0: ?[]const u8 = null; while (args.next()) |arg| { + if (arg0 == null) arg0 = arg; + if (std.mem.eql(u8, "-h", arg) or std.mem.eql(u8, "--help", arg)) { + try stdout.print( + \\usage: {?s} [-h|--help] [-v][-v][-v] [test_name...] + \\ + \\Where tests are one of the following: + \\ + , .{arg0}); + inline for (std.meta.fields(Tests)) |enumfield| { + try stdout.print("* {s}\n", .{enumfield.name}); + } + return; + } if (std.mem.eql(u8, "-v", arg)) { verbose += 1; continue;