Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions gozero.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ func (g *Gozero) Eval(ctx context.Context, src, input *Source, args ...string) (
return gcmd.Execute(ctx)
}

// EvalWithVirtualEnv evaluates the source code in a virtual environment and returns the output
// This function passes the source code into the virtual environment and external parameters as environment variables
// EvalWithVirtualEnv evaluates the source code in a virtual environment and
// returns the output. As in Eval, the engine gets Options.Args before the
// source path and args after it, input is the standard input, and the
// variables of src and input are environment variables. A source that starts
// with a shebang runs directly, without the engine and Options.Args.
func (g *Gozero) EvalWithVirtualEnv(ctx context.Context, envType VirtualEnvType, src, input *Source, dockerConfig *sandbox.DockerConfiguration, args ...string) (*types.Result, error) {
// Read source code content
srcContent, err := src.ReadAll()
Expand Down Expand Up @@ -119,7 +122,12 @@ func (g *Gozero) EvalWithVirtualEnv(ctx context.Context, envType VirtualEnvType,
}

// Execute the source code in the Docker container
result, err := dockerSandbox.RunSource(ctx, string(srcContent), interpreter)
result, err := dockerSandbox.RunSourceWithOptions(ctx, string(srcContent), sandbox.DockerSourceOptions{
Interpreter: interpreter,
InterpreterArgs: g.Options.Args,
Args: args,
Stdin: input.File,
})
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions sandbox/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import "errors"
var (
ErrNotImplemented = errors.New("not implemented")
ErrAgentRequired = errors.New("requires agent installed on the sandbox")

errEmptyCommand = errors.New("empty command")
)
Loading
Loading