Skip to content

Commit 97a344b

Browse files
committed
added support for defining running servicecs on the fly
1 parent 00e32b5 commit 97a344b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cmd/services_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var svcRunCmd = &cobra.Command{
1212

1313
Run: func(cmd *cobra.Command, args []string) {
1414
pm := support.NewPM(cfg)
15-
pm.Run()
15+
pm.Run(args)
1616
},
1717
}
1818

support/pm.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
type PM struct {
1515
config Config
16+
services []string // Specific services to run, if empty, run all from config
1617
}
1718

1819
func NewPM(cfg Config) *PM {
@@ -21,14 +22,30 @@ func NewPM(cfg Config) *PM {
2122
}
2223
}
2324

24-
func (pm *PM) Run() {
25+
func (pm *PM) Run(services []string) {
26+
for _, s := range services {
27+
hasService := false
28+
for name, _ := range pm.config.Services {
29+
if name == s {
30+
hasService = true
31+
}
32+
}
33+
if !hasService {
34+
fmt.Println("Could not find service " + s)
35+
os.Exit(1)
36+
}
37+
}
38+
pm.services = services
2539
pm.start()
2640
waitSig()
2741
pm.stop()
2842
}
2943

3044
func (pm *PM) start() {
3145
for name, svc := range pm.config.Services {
46+
if len(pm.services) != 0 && !StringInSlice(name, pm.services) {
47+
continue
48+
}
3249
svc.name = name
3350

3451
if svc.Build != "" {
@@ -47,6 +64,9 @@ func (pm *PM) start() {
4764

4865
func (pm *PM) stop() {
4966
for _, svc := range pm.config.Services {
67+
if len(pm.services) != 0 && !StringInSlice(svc.name, pm.services) {
68+
continue
69+
}
5070
pm.kill(svc, true)
5171
}
5272
}

0 commit comments

Comments
 (0)