-
Notifications
You must be signed in to change notification settings - Fork 58
/
service.go
47 lines (39 loc) · 1.12 KB
/
service.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
package service
import (
"fmt"
"strings"
"github.com/jakewright/home-automation/tools/bolt/pkg/compose"
"github.com/jakewright/home-automation/tools/bolt/pkg/config"
)
// Expand turns a list of arguments into a
// set of services by expanding the groups.
func Expand(args []string) []string {
var services []string
for _, s := range args {
services = append(services, expandService(s)...)
}
return services
}
// expandService returns the set of services
// if s is a group name otherwise s
func expandService(s string) []string {
for groupName, services := range config.Get().Groups {
if s == groupName {
return services
}
}
// To allow the user to specify the directory of the service instead of
// just the service name, strip the potential prefixes off the string.
s = strings.TrimPrefix(s, "service/")
s = strings.TrimPrefix(s, "./service/")
return []string{s}
}
// Run runs a set of services using the given Compose
func Run(c *compose.Compose, services []string) error {
for _, s := range services {
if err := c.Run(s); err != nil {
return fmt.Errorf("failed to run service: %w", err)
}
}
return nil
}