diff options
author | 2021-10-26 16:49:34 -0700 | |
---|---|---|
committer | 2021-10-26 16:49:34 -0700 | |
commit | 7d554ed1756c94ba0e37dd8d034ad5e60ee06df2 (patch) | |
tree | 10edfc6df57d1581d6841a66c9416741dc900fb9 | |
parent | e72d7659614e5294e0ee318850eee3a9f605ea56 (diff) | |
download | bun-7d554ed1756c94ba0e37dd8d034ad5e60ee06df2.tar.gz bun-7d554ed1756c94ba0e37dd8d034ad5e60ee06df2.tar.zst bun-7d554ed1756c94ba0e37dd8d034ad5e60ee06df2.zip |
[bun run] Fix passthrough behavior
-rw-r--r-- | src/cli/run_command.zig | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index c0f994ec7..3a8039978 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -402,8 +402,46 @@ pub const RunCommand = struct { var passthrough: []const string = &[_]string{}; - if (positionals.len > 1) { - passthrough = positionals[1..]; + var passthrough_list = std.ArrayList(string).init(ctx.allocator); + if (script_name_to_search.len > 0) { + get_passthrough: { + + // If they explicitly pass "--", that means they want everything after that to be passed through. + for (std.os.argv) |argv, i| { + if (strings.eqlComptime(std.mem.span(argv), "--")) { + if (std.os.argv.len > i + 1) { + var count: usize = 0; + for (std.os.argv[i + 1 ..]) |arg| { + count += 1; + } + try passthrough_list.ensureTotalCapacity(count); + + for (std.os.argv[i + 1 ..]) |arg| { + passthrough_list.appendAssumeCapacity(std.mem.span(arg)); + } + + passthrough = passthrough_list.toOwnedSlice(); + break :get_passthrough; + } + } + } + + // If they do not pass "--", assume they want everything after the script name to be passed through. + for (std.os.argv) |argv, i| { + if (strings.eql(std.mem.span(argv), script_name_to_search)) { + if (std.os.argv.len > i + 1) { + try passthrough_list.ensureTotalCapacity(std.os.argv[i + 1 ..].len); + + for (std.os.argv[i + 1 ..]) |arg| { + passthrough_list.appendAssumeCapacity(std.mem.span(arg)); + } + + passthrough = passthrough_list.toOwnedSlice(); + break :get_passthrough; + } + } + } + } } var did_print = false; |