Commits · ampify

tav  ·  b795306edd5c48b5494125e3492e98534da99d93  ·  ampify  ·  github 1311653066

Added starting amp repo and store to the amp run call.

Changes

src/amp/amp/run.go
......@@ -12,7 +12,7 @@ import (
1212
 	"time"
1313
 )
1414
 
15
-func runProcess(amp, cmd, path, config string, console bool) {
15
+func runProcess(amp, cmd, path, config string, console bool, quit chan bool) {
1616
 
1717
 	var files []*os.File
1818
 
......@@ -39,9 +39,25 @@ func runProcess(amp, cmd, path, config string, console bool) {
3939
 	if err != nil {
4040
 		runtime.StandardError(err)
4141
 	}
42
+
43
+	quit <- true
44
+
4245
 }
4346
 
44
-func run(argv []string, usage string) {
47
+func ensureDirectory(root, path string) (directory string) {
48
+	if path == "" {
49
+		directory = root
50
+	} else {
51
+		directory = runtime.JoinPath(root, path)
52
+	}
53
+	_, err := os.Open(directory)
54
+	if err != nil {
55
+		runtime.StandardError(err)
56
+	}
57
+	return
58
+}
59
+
60
+func ampRun(argv []string, usage string) {
4561
 
4662
 	opts := optparse.Parser(
4763
 		"Usage: amp run <instance-path> [options]\n\n    " + usage + "\n")
......@@ -49,11 +65,17 @@ func run(argv []string, usage string) {
4965
 	profile := opts.String([]string{"--profile"}, "development",
5066
 		"the config profile to use [development]", "NAME")
5167
 
52
-	frontendPath := opts.String([]string{"--frontend"}, "frontend",
53
-		"the path to the frontend directory [frontend]", "PATH")
68
+	repoPath := opts.String([]string{"--repo"}, "repo",
69
+		"the path to the amp repo directory [repo]", "PATH")
70
+
71
+	storePath := opts.String([]string{"--store"}, "store",
72
+		"the path to the amp store directory [store]", "PATH")
5473
 
5574
 	nodePath := opts.String([]string{"--node"}, "node",
56
-		"the path to the node directory [node]", "PATH")
75
+		"the path to the amp node directory [node]", "PATH")
76
+
77
+	frontendPath := opts.String([]string{"--frontend"}, "frontend",
78
+		"the path to the amp frontend directory [frontend]", "PATH")
5779
 
5880
 	noConsoleLog := opts.Bool([]string{"--no-console-log"}, false,
5981
 		"disable output to stdout/stderr")
......@@ -70,44 +92,29 @@ func run(argv []string, usage string) {
7092
 		runtime.StandardError(err)
7193
 	}
7294
 
73
-	_, err = os.Open(root)
74
-	if err != nil {
75
-		runtime.StandardError(err)
76
-	}
77
-
78
-	frontendDirectory := runtime.JoinPath(root, *frontendPath)
79
-	_, err = os.Open(frontendDirectory)
80
-	if err != nil {
81
-		runtime.StandardError(err)
82
-	}
83
-
84
-	nodeDirectory := runtime.JoinPath(root, *nodePath)
85
-	_, err = os.Open(nodeDirectory)
86
-	if err != nil {
87
-		runtime.StandardError(err)
88
-	}
89
-
9095
 	amp, err := exec.LookPath("amp")
9196
 	if err != nil {
9297
 		runtime.StandardError(err)
9398
 	}
9499
 
95
-	runtime.Init()
96100
 	config := *profile + ".yaml"
101
+	console := !*noConsoleLog
102
+	quit := make(chan bool, 1)
97103
 
98
-	console := true
99
-	if *noConsoleLog {
100
-		console = false
104
+	runtime.Init()
105
+	ensureDirectory(root, "")
106
+
107
+	for _, spec := range [][]string{
108
+		{"repo", ensureDirectory(root, *repoPath)},
109
+		{"store", ensureDirectory(root, *storePath)},
110
+		{"node", ensureDirectory(root, *nodePath)},
111
+		{"frontend", ensureDirectory(root, *frontendPath)},
112
+	} {
113
+		go runProcess(amp, spec[0], spec[1], config, console, quit)
114
+		<-time.After(2000000000)
101115
 	}
102116
 
103
-	go runProcess(amp, "frontend", frontendDirectory, config, console)
104
-
105
-	<-time.After(2000000000)
106
-
107
-	go runProcess(amp, "node", nodeDirectory, config, console)
108
-
109117
 	// Enter the wait loop for the process to be killed.
110
-	loopForever := make(chan bool, 1)
111
-	<-loopForever
118
+	<-quit
112119
 
113120
 }