-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
50 lines (41 loc) · 1.05 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/PaulRosset/previs/api"
)
func whichConfig(args []string) string {
if len(args) == 1 && args[0] == "-p" {
fmt.Println("You are using '.previs.yml' file")
return ".previs.yml"
}
fmt.Println("You are using '.travis.yml' file")
return ".travis.yml"
}
func main() {
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "error encountered: %+v\n", err)
os.Exit(2)
}
configFile := whichConfig(os.Args[1:])
runner, err := api.FromConfig(cwd + "/" + configFile)
if err != nil {
die("An error occurred: %+v\n", err)
}
imgDocker, envsVar, services, err := runner.WriteDockerfile()
if err != nil {
api.CleanUnusedDockerfile(cwd, imgDocker)
die("An error occurred: %+v\n", err)
}
err = api.Start(imgDocker, cwd+"/", envsVar, services)
if err != nil {
api.CleanUnusedDockerfile(cwd, imgDocker)
die("An error occurred: %+v\n", err)
}
}
// Print a message and exit with a status code of 2.
func die(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg, args...)
os.Exit(2)
}