1
0
mirror of https://github.com/go-task/task.git synced 2025-01-06 03:53:54 +02:00

execext: Small refactor

This commit is contained in:
Andrey Nering 2020-12-27 16:49:51 -03:00
parent cb96a39b46
commit 16fad60833

View File

@ -48,14 +48,7 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
r, err := interp.New(
interp.Dir(opts.Dir),
interp.Env(expand.ListEnviron(environ...)),
interp.OpenHandler(func(ctx context.Context, path string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
if path == "/dev/null" {
return devNull{}, nil
}
return interp.DefaultOpenHandler()(ctx, path, flag, perm)
}),
interp.OpenHandler(openHandler),
interp.StdIO(opts.Stdin, opts.Stdout, opts.Stderr),
)
if err != nil {
@ -86,3 +79,10 @@ func Expand(s string) (string, error) {
}
return "", nil
}
func openHandler(ctx context.Context, path string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
if path == "/dev/null" {
return devNull{}, nil
}
return interp.DefaultOpenHandler()(ctx, path, flag, perm)
}