This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
92 lines (77 loc) · 1.73 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"flag"
"fmt"
"github.com/marmelab/gaudi/gaudi"
"github.com/marmelab/gaudi/util"
"os"
"strings"
)
type stringSlice []string
func (s *stringSlice) String() string {
return strings.Join(*s, " ")
}
func (s *stringSlice) Set(value string) error {
*s = append(*s, value)
return nil
}
var (
config = flag.String("config", ".gaudi.yml", "File describing the architecture")
flagVersion = flag.Bool("v", false, "Display version")
)
func main() {
flag.Parse()
if *flagVersion {
fmt.Println(gaudi.VERSION)
return
}
rebuild := len(flag.Args()) > 0 && flag.Args()[0] == "rebuild"
g := gaudi.Gaudi{}
g.InitFromFile(retrieveConfigPath(*config))
if len(flag.Args()) == 0 || rebuild {
// Start all applications
g.StartApplications(rebuild)
} else {
switch os.Args[1] {
case "run":
// Run a specific command
g.Run(os.Args[2], os.Args[3:])
break
case "enter":
// Enter in a specific container
g.Enter(os.Args[2])
break
case "stop":
// Stop all applications
g.StopApplications()
break
case "check":
// Check if all applications are running
g.Check()
break
case "clean":
// Clean application containers
g.Clean()
break
default:
util.LogError("Argument " + os.Args[1] + " was not found")
break
}
}
}
func retrieveConfigPath(configFile string) string {
if len(configFile) == 0 {
util.LogError("Config file name cannot be empty.")
}
if string(configFile[0]) != "/" {
currentDir, err := os.Getwd()
if err != nil {
util.LogError(err)
}
configFile = currentDir + "/" + configFile
}
if !util.IsFile(configFile) {
util.LogError("Configuration file not found: '" + configFile + "'. Use --config to specify a custom file")
}
return configFile
}