Commit 3414f1a

Jay Hemnani  ·  2026-10-16 09:27:42 -0400 EDT
parent ce8b2bd
fix(run): only treat -d as a flag before the command (#275)

zmx run dropped every argument that starts with -d, wherever it appeared,
and ran the session detached. So `zmx run dev cut -d: -f1 file` ran
`cut -f1 file` in the background. Stop looking for -d once the command
has started, like attach does for its flags.
2 files changed,  +9, -1
+2, -1
......@@ -208,7 +208,8 @@ pub fn main(init: std.process.Init) !void {
208208 defer cmd_args_raw.deinit(gpa);
209209 var detached = false;
210210 while (args.next()) |arg| {
211- if (std.mem.startsWith(u8, arg, "-d")) {
211+ // Once the command has started, -d belongs to the command.
212+ if (cmd_args_raw.items.len == 0 and std.mem.startsWith(u8, arg, "-d")) {
212213 detached = true;
213214 } else {
214215 try cmd_args_raw.append(gpa, arg);
+7, -0
......@@ -45,6 +45,13 @@ load test_helper
4545 [[ "$output" == *"session \"test-blocking\" created"* ]]
4646 }
4747
48+@test "run: -d after the command is passed to the command" {
49+ run timeout 5 "$ZMX" run test-dash-d printf 'arg=%s\n' -d
50+ [ "$status" -eq 0 ]
51+ [[ "$output" != *"command sent"* ]]
52+ wait_for_output test-dash-d "arg=-d"
53+}
54+
4855 @test "run: requires a command argument" {
4956 run "$ZMX" run test-nocmd
5057 [ "$status" -ne 0 ]