-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomposer.go
59 lines (47 loc) · 1.07 KB
/
composer.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
package main
import (
"flag"
"fmt"
"os"
"github.com/t12y/composer/composer"
)
const errCode = 1
func main() {
composerFile := os.Getenv("COMPOSER_FILE")
if composerFile == "" {
composerFile = "composer.yml"
}
cfg, err := composer.ParseConfig(composerFile)
if err != nil {
fmt.Println("Cannot parse config:", err)
os.Exit(errCode)
}
var waitForAll bool
flag.BoolVar(&waitForAll, "wait", false, "wait for all services to finish")
flag.Parse()
if len(os.Args) <= 1 {
fmt.Printf("\nUsage: %s [options] SERVICE [SERVICE ...]\n\nOptions:\n", os.Args[0])
flag.PrintDefaults()
fmt.Println("\nServices:")
for service := range cfg.Services {
fmt.Println(" -", service)
}
fmt.Println("")
os.Exit(errCode)
}
services := flag.Args()
var c *composer.Composer
if c, err = composer.New(*cfg, services...); err != nil {
fmt.Println("Error initializing composer:", err)
os.Exit(errCode)
}
if waitForAll {
err = c.RunAll(services...)
} else {
err = c.Run()
}
if err != nil {
fmt.Println("Error running composer:", err)
os.Exit(errCode)
}
}