Commits · ampify

tav  ·  3afd077aba2aa28874159aaf82a66e5bb627f9a2  ·  ampify  ·  github 1311828190

Updated the amp build and test commands.

Changes

src/amp/amp/node.go
......@@ -4,9 +4,10 @@
44
 package main
55
 
66
 import (
7
+	"amp/logging"
8
+	"amp/master"
79
 	"amp/nodule"
810
 	"amp/optparse"
9
-	"amp/repo"
1011
 	"amp/runtime"
1112
 	"os"
1213
 	"strings"
......@@ -35,33 +36,40 @@ func ampNode(argv []string, usage string) {
3536
 	nodulePaths := opts.StringConfig("nodule-paths", ".",
3637
 		"comma-separated list of nodule container directories [nodule]")
3738
 
38
-	repoNodes := opts.StringConfig("repo-nodes", "localhost:8060",
39
-		"comma-separated addresses of amp repo nodes [localhost:8060]")
39
+	masterNodes := opts.StringConfig("master-nodes", "localhost:8060",
40
+		"comma-separated addresses of amp master nodes [localhost:8060]")
4041
 
41
-	repoKeyPath := opts.StringConfig("repo-key", "cert/repo.key",
42
-		"the path to the file containing the amp repo public key [cert/repo.key]")
42
+	masterKeyPath := opts.StringConfig("master-key", "cert/master.key",
43
+		"the path to the file containing the amp master public key [cert/master.key]")
4344
 
4445
 	debug, _, runPath := runtime.DefaultOpts("node", opts, argv, nil)
4546
 
46
-	repoClient, err := repo.NewClient(*repoNodes, *repoKeyPath)
47
+	masterClient, err := master.NewClient(*masterNodes, *masterKeyPath)
4748
 
4849
 	if err != nil {
4950
 		runtime.StandardError(err)
5051
 	}
5152
 
53
+	logging.AddConsoleFilter(nodule.FilterConsoleLog)
54
+
5255
 	node, err := nodule.NewHost(
5356
 		runPath, *nodeHost, *nodePort, *ctrlHost, *ctrlPort, *nodules,
54
-		strings.SplitN(*nodulePaths, ",", -1), repoClient)
57
+		strings.SplitN(*nodulePaths, ",", -1), masterClient)
5558
 
5659
 	if err != nil {
5760
 		runtime.StandardError(err)
5861
 	}
5962
 
60
-	node.Run(debug)
63
+	err = node.Run(debug)
64
+	logging.Wait()
65
+
66
+	if err != nil {
67
+		runtime.Exit(1)
68
+	}
6169
 
6270
 }
6371
 
64
-func getNodules(paths []string) (nodules [][]string) {
72
+func getNodules(paths []string) (nodules []*nodule.Nodule) {
6573
 
6674
 	if paths == nil {
6775
 		cwd, err := os.Getwd()
......@@ -71,7 +79,7 @@ func getNodules(paths []string) (nodules [][]string) {
7179
 		paths = []string{cwd}
7280
 	}
7381
 
74
-	nodules = make([][]string, 0)
82
+	nodules = make([]*nodule.Nodule, 0)
7583
 	seen := make(map[string]bool)
7684
 
7785
 	for _, path := range paths {
......@@ -79,12 +87,12 @@ func getNodules(paths []string) (nodules [][]string) {
7987
 		if err != nil {
8088
 			runtime.StandardError(err)
8189
 		}
82
-		for name, confpath := range data {
83
-			if seen[confpath] {
90
+		for _, nodule := range data {
91
+			if seen[nodule.Path] {
8492
 				continue
8593
 			}
86
-			nodules = append(nodules, []string{name, confpath})
87
-			seen[confpath] = true
94
+			nodules = append(nodules, nodule)
95
+			seen[nodule.Path] = true
8896
 		}
8997
 	}
9098
 
......@@ -92,38 +100,85 @@ func getNodules(paths []string) (nodules [][]string) {
92100
 
93101
 }
94102
 
95
-func ampBuild(argv []string, usage string) {
103
+func handleCommon(name, usage string, argv []string) (args []string) {
96104
 
97105
 	opts := optparse.Parser(
98
-		"Usage: amp build <path> [options]\n\n    " + usage + "\n")
106
+		"Usage: amp " + name + " <path> [options]\n\n    " + usage + "\n")
99107
 
100
-	args := opts.Parse(argv)
108
+	profile := opts.String([]string{"--profile"}, "development",
109
+		"the config profile to use [development]", "NAME")
110
+
111
+	noConsoleLog := opts.Bool([]string{"--no-console-log"}, false,
112
+		"disable output to stdout/stderr")
113
+
114
+	args = opts.Parse(argv)
101115
 
102116
 	if len(args) == 0 {
103117
 		opts.PrintUsage()
104118
 		runtime.Exit(0)
105119
 	}
106120
 
107
-	for _, info := range getNodules(args) {
108
-		nodule.Build(info[0], info[1])
121
+	runtime.SetProfile(*profile)
122
+
123
+	if !*noConsoleLog {
124
+		logging.AddConsoleLogger()
125
+		logging.AddConsoleFilter(nodule.FilterConsoleLog)
109126
 	}
110127
 
128
+	return
129
+
111130
 }
112131
 
113
-func ampTest(argv []string, usage string) {
132
+func ampBuild(argv []string, usage string) {
114133
 
115
-	opts := optparse.Parser(
116
-		"Usage: amp test <path> [options]\n\n    " + usage + "\n")
134
+	args := handleCommon("build", usage, argv)
135
+	status := 0
117136
 
118
-	args := opts.Parse(argv)
137
+	for _, nodule := range getNodules(args) {
138
+		err := nodule.Build()
139
+		if err != nil {
140
+			status = 1
141
+			break
142
+		}
143
+	}
119144
 
120
-	if len(args) == 0 {
121
-		opts.PrintUsage()
122
-		runtime.Exit(0)
145
+	logging.Wait()
146
+	runtime.Exit(status)
147
+
148
+}
149
+
150
+func ampTest(argv []string, usage string) {
151
+
152
+	args := handleCommon("test", usage, argv)
153
+	status := 0
154
+
155
+	for _, nodule := range getNodules(args) {
156
+		err := nodule.Test()
157
+		if err != nil {
158
+			status = 1
159
+			break
160
+		}
123161
 	}
124162
 
125
-	for _, info := range getNodules(args) {
126
-		nodule.Test(info[0], info[1])
163
+	logging.Wait()
164
+	runtime.Exit(status)
165
+
166
+}
167
+
168
+func ampReview(argv []string, usage string) {
169
+
170
+	args := handleCommon("review", usage, argv)
171
+	status := 0
172
+
173
+	for _, nodule := range getNodules(args) {
174
+		err := nodule.Review()
175
+		if err != nil {
176
+			status = 1
177
+			break
178
+		}
127179
 	}
128180
 
181
+	logging.Wait()
182
+	runtime.Exit(status)
183
+
129184
 }