-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
145 lines (116 loc) · 3.32 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright 2015 Palm Stone Games, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"errors"
"flag"
"fmt"
"os"
"os/exec"
"path"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
)
const DocUsage = `gb gae is a tool for managing Google Appengine applications with gb.
Usage:
gb gae command [arguments]
The commands are:
serve starts a local development App Engine server
deploy deploys your application to App Engine
build compile packages and dependencies
test test packages
raw Directly call the dev_appserver.py
appcfg Directly call the appcfg.py
gcloud Directly call the gcloud command.
`
var (
projectRoot string
)
func main() {
// Setup flags
fs := flag.NewFlagSet("gb-gae", flag.ExitOnError)
fs.StringVar(&projectRoot, "R", os.Getenv("GB_PROJECT_DIR"), "set the project root")
err := cmd.RunCommand(fs, &cmd.Command{
Run: run,
}, os.Getenv("GB_PROJECT_DIR"), "", os.Args[1:])
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
}
func run(ctx *gb.Context, args []string) error {
if len(args) == 0 {
return errors.New(DocUsage)
}
// Build up the fake env
env := cmd.MergeEnv(os.Environ(), map[string]string{
"GOPATH": fmt.Sprintf("%s%s%s", projectRoot, string(os.PathListSeparator), path.Join(projectRoot, "vendor")),
})
// Switch on the subcommand
switch args[0] {
case "serve", "deploy", "build", "test":
return goapp(ctx, args, env)
case "raw":
return raw(ctx, args, env)
case "appcfg":
return appcfg(ctx, args, env)
case "gcloud":
return gcloud(ctx, args, env)
default:
return fmt.Errorf("Unknown subcommand: %s\n\n%v", args[0], DocUsage)
}
}
func goapp(ctx *gb.Context, args []string, env []string) error {
app := exec.Command("goapp", args...)
app.Stdin = os.Stdin
app.Stdout = os.Stdout
app.Stderr = os.Stderr
app.Env = env
if err := app.Run(); err != nil {
return fmt.Errorf("Failed to run goapp command: %v", err)
}
return nil
}
func gcloud(ctx *gb.Context, args []string, env []string) error {
app := exec.Command("gcloud", args[1:]...)
app.Stdin = os.Stdin
app.Stdout = os.Stdout
app.Stderr = os.Stderr
app.Env = env
if err := app.Run(); err != nil {
return fmt.Errorf("Failed to run gcloud command: %v", err)
}
return nil
}
func raw(ctx *gb.Context, args []string, env []string) error {
app := exec.Command("dev_appserver.py", args[1:]...)
app.Stdin = os.Stdin
app.Stdout = os.Stdout
app.Stderr = os.Stderr
app.Env = env
if err := app.Run(); err != nil {
return fmt.Errorf("Failed to run dev_appserver.py: %v", err)
}
return nil
}
func appcfg(ctx *gb.Context, args []string, env []string) error {
app := exec.Command("appcfg.py", args[1:]...)
app.Stdin = os.Stdin
app.Stdout = os.Stdout
app.Stderr = os.Stderr
app.Env = env
if err := app.Run(); err != nil {
return fmt.Errorf("Failed to run appcfg.py: %v", err)
}
return nil
}