repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
bac7930
parent
060c4f5
author
Eric Bower
date
2025-12-03 23:02:00 -0500 EST
fix: print help text with unknown commands

We should print the help text when possible and refrain from using the
logger when the user provides invalid input since that gets sent to our
log files.

Closes: https://github.com/neurosnap/zmx/issues/11
1 files changed,  +8, -7
M src/main.zig
+8, -7
 1@@ -136,7 +136,7 @@ pub fn main() !void {
 2         return list(&cfg);
 3     };
 4 
 5-    if (std.mem.eql(u8, cmd, "help") or std.mem.eql(u8, cmd, "h")) {
 6+    if (std.mem.eql(u8, cmd, "help") or std.mem.eql(u8, cmd, "h") or std.mem.eql(u8, cmd, "-h")) {
 7         return help();
 8     } else if (std.mem.eql(u8, cmd, "list") or std.mem.eql(u8, cmd, "l")) {
 9         return list(&cfg);
10@@ -144,14 +144,12 @@ pub fn main() !void {
11         return detachAll(&cfg);
12     } else if (std.mem.eql(u8, cmd, "kill") or std.mem.eql(u8, cmd, "k")) {
13         const session_name = args.next() orelse {
14-            std.log.err("session name required", .{});
15-            return;
16+            return error.SessionNameRequired;
17         };
18         return kill(&cfg, session_name);
19     } else if (std.mem.eql(u8, cmd, "attach") or std.mem.eql(u8, cmd, "a")) {
20         const session_name = args.next() orelse {
21-            std.log.err("session name required", .{});
22-            return;
23+            return error.SessionNameRequired;
24         };
25 
26         var command_args: std.ArrayList([]const u8) = .empty;
27@@ -179,7 +177,7 @@ pub fn main() !void {
28         std.log.info("socket path={s}", .{daemon.socket_path});
29         return attach(&daemon);
30     } else {
31-        std.log.err("unknown cmd={s}", .{cmd});
32+        return help();
33     }
34 }
35 
36@@ -197,7 +195,10 @@ fn help() !void {
37         \\  [h]elp                        Show this help message
38         \\
39     ;
40-    try std.fs.File.stdout().writeAll(help_text);
41+    var buf: [4096]u8 = undefined;
42+    var w = std.fs.File.stdout().writer(&buf);
43+    try w.interface.print(help_text, .{});
44+    try w.interface.flush();
45 }
46 
47 fn list(cfg: *Cfg) !void {