-
Notifications
You must be signed in to change notification settings - Fork 2
/
exec.go
136 lines (109 loc) · 3.38 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package puffin
import (
"context"
"io"
"os"
"os/exec"
"syscall"
)
// OsExec is an Exec implementation that uses os/exec functions
type OsExec struct{}
// NewOsExec creates a new OsExec struct
func NewOsExec() Exec {
return &OsExec{}
}
// Lookpath behaves the same as exec.LookPath https://pkg.go.dev/os/exec#LookPath
func (*OsExec) LookPath(file string) (string, error) {
return exec.LookPath(file)
}
// Command behaves the same as exec.Command https://pkg.go.dev/os/exec#Command
func (*OsExec) Command(name string, arg ...string) Cmd {
return &OsCmd{Cmd: exec.Command(name, arg...)}
}
// CommandContext behaves the same as exec.CommandContext https://pkg.go.dev/os/exec#CommandContext
func (*OsExec) CommandContext(ctx context.Context, name string, arg ...string) Cmd {
return &OsCmd{Cmd: exec.CommandContext(ctx, name, arg...)}
}
type OsCmd struct {
*exec.Cmd
}
// Path returns the Cmd path https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Path() string {
return c.Cmd.Path
}
// SetPath sets the Cmd path https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetPath(path string) {
c.Cmd.Path = path
}
// Args returns the Cmd args https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Args() []string {
return c.Cmd.Args
}
// SetArgs sets the Cmd args https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetArgs(args []string) {
c.Cmd.Args = args
}
// Env returns the Cmd env https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Env() []string {
return c.Cmd.Env
}
// SetEnv sets the Cmd env https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetEnv(env []string) {
c.Cmd.Env = env
}
// Dir returns the Cmd working dir https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Dir() string {
return c.Cmd.Dir
}
// SetDir sets the Cmd working dir https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetDir(dir string) {
c.Cmd.Dir = dir
}
// Stdin returns the Cmd Stdin https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Stdin() io.Reader {
return c.Cmd.Stdin
}
// SetStdin sets the Cmd Stdin https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetStdin(stdin io.Reader) {
c.Cmd.Stdin = stdin
}
// Stdout returns the Cmd Stdout https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Stdout() io.Writer {
return c.Cmd.Stdout
}
// SetStdout sets the Cmd Stdout https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetStdout(stdout io.Writer) {
c.Cmd.Stdout = stdout
}
// Stderr returns the Cmd Stderr https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Stderr() io.Writer {
return c.Cmd.Stderr
}
// SetStderr sets the Cmd Stderr https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetStderr(stderr io.Writer) {
c.Cmd.Stderr = stderr
}
// ExtraFiles returns the Cmd extra files https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) ExtraFiles() []*os.File {
return c.Cmd.ExtraFiles
}
// SetExtraFiles sets the Cmd extra files https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SetExtraFiles(extraFiles []*os.File) {
c.Cmd.ExtraFiles = extraFiles
}
// SysProcAttr returns the Cmd sys proc attr https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) SysProcAttr() *syscall.SysProcAttr {
return c.Cmd.SysProcAttr
}
// Process returns the Cmd process https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Process() *os.Process {
return c.Cmd.Process
}
// ProcessState returns the Cmd process state https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) ProcessState() *os.ProcessState {
return c.Cmd.ProcessState
}
// Err returns the Cmd err https://pkg.go.dev/os/exec#Cmd
func (c *OsCmd) Err() error {
return c.Cmd.Err
}