-
Notifications
You must be signed in to change notification settings - Fork 0
/
ops.go
69 lines (60 loc) · 1.16 KB
/
ops.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
package ops
type Ops struct {
conf *Opsfile
debug bool
dryRun bool
}
type OpsOption func(*Ops)
func WithDebug(debug bool) OpsOption {
return func(o *Ops) {
o.debug = debug
}
}
func WithDryRun(dryRun bool) OpsOption {
return func(o *Ops) {
o.dryRun = dryRun
}
}
func NewOps(conf *Opsfile, options ...OpsOption) *Ops {
ops := &Ops{conf: conf}
for _, v := range options {
v(ops)
}
return ops
}
type ConnectError struct {
Host string
Err error
}
type RunError struct {
host string
err error
}
type ParseError struct {
target string
Err error
}
func (te *RunError) Error() string {
return te.err.Error()
}
func (ce *ConnectError) Error() string {
return ce.Err.Error()
}
func (pe *ParseError) Error() string {
return pe.Err.Error()
}
// Run
func (ops *Ops) Run(serverTag string, tasks ...string) error {
cp := &connectorPreparer{}
connectors := cp.Prepare(ops.conf, serverTag)
ctp := &connectorTaskPreparer{}
connectorTasks, err := ctp.Prepare(ops.conf, tasks...)
if err != nil {
return err
}
exec := NewExecutor(ops.conf, ops.debug, ops.dryRun)
if err := exec.Execute(connectorTasks, connectors); err != nil {
return err
}
return nil
}