-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
51 lines (47 loc) · 1.03 KB
/
options.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
41
42
43
44
45
46
47
48
49
50
51
package sh
import "github.com/zdz1715/go-sh/shell"
type ExecOptions struct {
IDCreator IDCreator
Shell *shell.Shell
Storage *Storage
User string
WorkDir string
Output func(num int, line []byte)
}
func (e *ExecOptions) Copy() *ExecOptions {
return &ExecOptions{
IDCreator: e.IDCreator,
Shell: e.Shell,
Storage: e.Storage,
User: e.User,
WorkDir: e.WorkDir,
Output: e.Output,
}
}
func GlobalExecOptionsOverwrite(opts ...*ExecOptions) *ExecOptions {
if len(opts) == 0 || opts[0] == nil {
return gExecOptions
}
eCopy := opts[0].Copy()
if gExecOptions != nil {
if eCopy.IDCreator == nil {
eCopy.IDCreator = gExecOptions.IDCreator
}
if eCopy.Shell == nil {
eCopy.Shell = gExecOptions.Shell
}
if eCopy.Storage == nil {
eCopy.Storage = gExecOptions.Storage
}
if eCopy.User == "" {
eCopy.User = gExecOptions.User
}
if eCopy.WorkDir == "" {
eCopy.WorkDir = gExecOptions.WorkDir
}
if eCopy.Output == nil {
eCopy.Output = gExecOptions.Output
}
}
return eCopy
}