-
Notifications
You must be signed in to change notification settings - Fork 496
/
main.go
90 lines (72 loc) · 1.71 KB
/
main.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
package ledgerbackend
import (
"io"
"io/fs"
"io/ioutil"
"os"
"os/exec"
)
type isDir interface {
IsDir() bool
}
type systemCaller interface {
removeAll(path string) error
writeFile(filename string, data []byte, perm fs.FileMode) error
mkdirAll(path string, perm os.FileMode) error
stat(name string) (isDir, error)
command(name string, arg ...string) cmdI
}
type realSystemCaller struct{}
func (realSystemCaller) removeAll(path string) error {
return os.RemoveAll(path)
}
func (realSystemCaller) writeFile(filename string, data []byte, perm fs.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
}
func (realSystemCaller) mkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
func (realSystemCaller) stat(name string) (isDir, error) {
return os.Stat(name)
}
func (realSystemCaller) command(name string, arg ...string) cmdI {
cmd := exec.Command(name, arg...)
return &realCmd{cmd}
}
type cmdI interface {
Output() ([]byte, error)
Wait() error
Start() error
Run() error
setDir(dir string)
setStdout(stdout io.Writer)
getStdout() io.Writer
setStderr(stderr io.Writer)
getStderr() io.Writer
getProcess() *os.Process
setExtraFiles([]*os.File)
}
type realCmd struct {
*exec.Cmd
}
func (r *realCmd) setDir(dir string) {
r.Cmd.Dir = dir
}
func (r *realCmd) setStdout(stdout io.Writer) {
r.Cmd.Stdout = stdout
}
func (r *realCmd) getStdout() io.Writer {
return r.Cmd.Stdout
}
func (r *realCmd) setStderr(stderr io.Writer) {
r.Cmd.Stderr = stderr
}
func (r *realCmd) getStderr() io.Writer {
return r.Cmd.Stderr
}
func (r *realCmd) getProcess() *os.Process {
return r.Cmd.Process
}
func (r *realCmd) setExtraFiles(extraFiles []*os.File) {
r.ExtraFiles = extraFiles
}