github.com/mattevans/edward@v1.9.2/edward/start.go (about) 1 package edward 2 3 import ( 4 "log" 5 6 "github.com/pkg/errors" 7 "github.com/mattevans/edward/services" 8 ) 9 10 func (c *Client) Start(names []string, skipBuild bool, noWatch bool, exclude []string) error { 11 log.Println("Start:", names, skipBuild, noWatch, exclude) 12 if len(names) == 0 { 13 if len(c.Backends) == 0 { 14 return errors.New("At least one service or group must be specified") 15 } 16 } 17 18 c.telemetryEvent(append([]string{"start"}, names...)...) 19 20 sgs, err := c.getServicesOrGroups(names) 21 if err != nil { 22 return errors.WithStack(err) 23 } 24 if startingServicesOnly(sgs) && len(c.Backends) != 0 { 25 names = append(getMissingServiceNamesFromBackends(c, names), names...) 26 sgs, err = c.getServicesOrGroups(names) 27 if err != nil { 28 return errors.WithStack(err) 29 } 30 } 31 if c.ServiceChecks != nil { 32 err = c.ServiceChecks(sgs) 33 if err != nil { 34 return errors.WithStack(err) 35 } 36 } 37 38 err = c.startAndTrack(sgs, skipBuild, noWatch, exclude, c.EdwardExecutable) 39 if err != nil { 40 return errors.WithStack(err) 41 } 42 return nil 43 } 44 45 func startingServicesOnly(sgs []services.ServiceOrGroup) bool { 46 return services.CountServices(sgs) == len(sgs) 47 } 48 49 func getMissingServiceNamesFromBackends(c *Client, existingNames []string) []string { 50 var existingNamesMap = make(map[string]struct{}) 51 for _, ename := range existingNames { 52 existingNamesMap[ename] = struct{}{} 53 } 54 55 names := make([]string, 0, len(c.Backends)) 56 for service := range c.Backends { 57 // Ensure we don't add duplicates 58 if _, exists := existingNamesMap[service]; exists { 59 continue 60 } 61 names = append(names, service) 62 } 63 return names 64 }