shell: implement $0, $1, argv accessors (#9740)

* shell: organize imports

* shell: dont allocate when printing errors

* shell: implement $0, $1, argv accessors

* add more tests

* oops need this commit too

* make these logs listen to silencing logs

* expand switch else statements

* align behavior with bash

* this isnt referenced anywhere

* add missing test file

* add another test

* revert this change

* cache utf8 converted version of positionals

* rebase fixes

---------

Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
This commit is contained in:
Meghan Denny
2024-04-02 23:07:27 -07:00
committed by GitHub
parent 268f13765c
commit bb483e8479
14 changed files with 325 additions and 70 deletions

View File

@@ -13,7 +13,7 @@ const open = @import("../open.zig");
const Command = bun.CLI.Command;
pub const ExecCommand = struct {
pub fn exec(ctx: Command.Context) !void {
pub fn exec(ctx: *Command.Context) !void {
const script = ctx.positionals[1];
// this is a hack: make dummy bundler so we can use its `.runEnvLoader()` function to populate environment variables probably should split out the functionality
var bundle = try bun.Bundler.init(
@@ -39,7 +39,7 @@ pub const ExecCommand = struct {
};
const script_path = bun.path.join(parts, .auto);
const code = bun.shell.Interpreter.initAndRunFromSource(mini, script_path, script) catch |err| {
const code = bun.shell.Interpreter.initAndRunFromSource(ctx, mini, script_path, script) catch |err| {
Output.prettyErrorln("<r><red>error<r>: Failed to run script <b>{s}<r> due to error <b>{s}<r>", .{ script_path, @errorName(err) });
Global.exit(1);
};