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 { | |
| 208 | 208 | defer cmd_args_raw.deinit(gpa); | |
| 209 | 209 | var detached = false; | |
| 210 | 210 | 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")) { | |
| 212 | 213 | detached = true; | |
| 213 | 214 | } else { | |
| 214 | 215 | try cmd_args_raw.append(gpa, arg); |
+7,
-0
| ... | ... | @@ -45,6 +45,13 @@ load test_helper | |
| 45 | 45 | [[ "$output" == *"session \"test-blocking\" created"* ]] | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 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 | + | ||
| 48 | 55 | @test "run: requires a command argument" { | |
| 49 | 56 | run "$ZMX" run test-nocmd | |
| 50 | 57 | [ "$status" -ne 0 ] |