-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
76 lines (66 loc) · 1.08 KB
/
host.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
package fresher
import (
"github.com/goccy/go-yaml"
)
type hostType int
const (
HostTypeLocal = iota
HostTypeDocker
)
const (
hostNameDocker = "docker"
)
func (h hostType) String() string {
switch h {
case HostTypeDocker:
return "docker"
default:
return "localhost"
}
}
type Host struct {
Type hostType
LocationName string
}
func (h *Host) UnmarshalYAML(b []byte) error {
m := make(map[string]string)
if err := yaml.Unmarshal(b, &m); err != nil {
return err
}
for host, location := range m {
h.Type = toHostType(host)
h.LocationName = location
break
}
return nil
}
func toHostType(host string) hostType {
switch host {
case hostNameDocker:
return HostTypeDocker
}
return HostTypeLocal
}
func (h *Host) RunCommand(path string) Executor {
switch h.Type {
case HostTypeDocker:
return &DockerCommand{
Command: &Command{
Name: "docker",
Arg: []string{
"exec",
h.LocationName,
path,
},
IsAsync: true,
},
binPath: path,
host: h,
}
default:
return &Command{
Name: path,
IsAsync: true,
}
}
}