-
Notifications
You must be signed in to change notification settings - Fork 0
/
swell.go
71 lines (60 loc) · 1.79 KB
/
swell.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
package main
import (
"flag"
"github.com/Sirupsen/logrus"
"os"
)
/**
* Swell should:
* X Read in configuration settings from swell.json, checking the current directory first and
* falling back to /etc/swell.conf.
* - Then check the command line params for the desired profiles.
* - For each profile, check to see that a directory exists at $CONFIG_BASE_PATH/$PROFILE and
* read all scripts.
* - Arrange the available scripts into an execution chain and start running them in forked processes.
* - Log all errors.
*/
var PROFILES_PATH = flag.String("profiles", "profiles/", "Root directory where all profiles are stored.")
func main() {
flag.Parse()
// Validate that this is an acceptable path. Throw an error if not.
path, err := GetProfilesPath(*PROFILES_PATH)
if err != nil {
logrus.Fatal(err.Error())
} else {
logrus.Info("Reading profiles from " + path)
}
// Create a configuration object, which for the time being only contains this path.
config := SwellConfig{
ProfilesPath: path,
}
// Load profiles
profiles, err := LoadProfiles(os.Args[1:], config)
if err != nil {
logrus.Fatal("Error reading profiles: " + err.Error())
}
logrus.Info("Available profiles:")
for _, profile := range profiles {
if profile.Enabled {
logrus.Info(" [run ] " + profile.Name)
} else {
logrus.Warn(" [skip] " + profile.Name)
}
}
logrus.Info("Running profiles:")
// Apply profiles in serial, and run all scripts serially for now as well.
for _, profile := range profiles {
if profile.Enabled {
logrus.Info(" [run ] " + profile.Name)
err = profile.Apply()
if err != nil {
logrus.WithFields(logrus.Fields{
"profile": profile.Name,
}).Warn(err.Error())
}
} else {
logrus.Warn(" [skip] " + profile.Name)
}
}
logrus.Info("Complete!")
}