-
Notifications
You must be signed in to change notification settings - Fork 520
/
exec.go
40 lines (34 loc) · 860 Bytes
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2013 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package exec provides a interface to run external commands as an
// abstraction layer.
package exec
import (
"io"
"os/exec"
)
// ExecuteOptions specify parameters to the Execute method.
type ExecuteOptions struct {
Cmd string
Args []string
Envs []string
Dir string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
type Executor interface {
// Execute executes the specified command.
Execute(opts ExecuteOptions) error
}
type OsExecutor struct{}
func (OsExecutor) Execute(opts ExecuteOptions) error {
c := exec.Command(opts.Cmd, opts.Args...)
c.Stdin = opts.Stdin
c.Stdout = opts.Stdout
c.Stderr = opts.Stderr
c.Env = opts.Envs
c.Dir = opts.Dir
return c.Run()
}