Repository navigation
Expand file tree
/
Copy pathglide.go
More file actions
283 lines (254 loc) · 8.2 KB
/
Copy pathglide.go
File metadata and controls
283 lines (254 loc) · 8.2 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// Glide is a command line utility that manages Go project dependencies and
// your GOPATH.
//
// Dependencies are managed via a glide.yaml in the root of a project. The yaml
// file lets you specify projects, versions (tags, branches, or references),
// and even alias one location in as other one. Aliasing is useful when supporting
// forks without needing to rewrite the imports in a codebase.
//
// A glide.yaml file looks like:
//
// package: github.com/Masterminds/glide
// imports:
// - package: github.com/Masterminds/cookoo
// vcs: git
// ref: 1.1.0
// subpackages: **
// - package: github.com/kylelemons/go-gypsy
// subpackages: yaml
//
// Glide puts dependencies in a _vendor directory. Go utilities require this to
// be in your GOPATH. Glide makes this easy. Use the `glide in` command to enter
// a shell (your default) with the GOPATH set to the projects _vendor directory.
// To leave this shell simply exit it.
//
// If your .bashrc, .zshrc, or other startup shell sets your GOPATH you many need
// to optionally set it using something like:
//
// if [ "" = "${GOPATH}" ]; then
// export GOPATH="/some/dir"
// fi
//
// For more information use the `glide help` command or see https://github.com/Masterminds/glide
package main
import (
"github.com/Masterminds/glide/cmd"
"github.com/Masterminds/cookoo"
"github.com/codegangsta/cli"
"fmt"
"os"
)
var version string = "0.2.0"
const Summary = "Manage Go projects with ease."
const Usage = `Manage dependencies, naming, and GOPATH for your Go projects.
Each project should have a 'glide.yaml' file in the project directory. Files
look something like this:
package: github.com/Masterminds/glide
imports:
- package: github.com/Masterminds/cookoo
vcs: git
ref: 1.1.0
subpackages: **
- package: github.com/kylelemons/go-gypsy
subpackages: yaml
`
func main() {
reg, router, cxt := cookoo.Cookoo()
routes(reg, cxt)
app := cli.NewApp()
app.Name = "glide"
app.Usage = Usage
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "yaml, y",
Value: "glide.yaml",
Usage: "Set a YAML configuration file.",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Quiet (no info or debug messages)",
},
}
app.CommandNotFound = func(c *cli.Context, command string) {
cxt.Put("os.Args", os.Args)
cxt.Put("command", command)
setupHandler(c, "@plugin", cxt, router)
}
app.Commands = commands(cxt, router)
app.Run(os.Args)
}
func commands(cxt cookoo.Context, router *cookoo.Router) []cli.Command {
return []cli.Command{
{
Name: "create",
ShortName: "init",
Usage: "Initialize a new project, creating a template glide.yaml",
Action: func(c *cli.Context) {
setupHandler(c, "create", cxt, router)
},
},
{
Name: "in",
Usage: "Glide into a commandline shell preconfigured for your project",
Action: func(c *cli.Context) {
setupHandler(c, "in", cxt, router)
},
},
{
Name: "install",
Usage: "Install all packages in the glide.yaml",
Action: func(c *cli.Context) {
setupHandler(c, "install", cxt, router)
},
},
{
Name: "into",
Usage: "The same as running \"cd /my/project && glide in\"",
Action: func(c *cli.Context) {
cxt.Put("toPath", c.Args()[0])
setupHandler(c, "into", cxt, router)
},
},
{
Name: "godeps",
Usage: "Import Godeps and Godeps-Git files and display the would-be yaml file",
Action: func(c *cli.Context) {
setupHandler(c, "godeps", cxt, router)
},
},
{
Name: "gopath",
8000
Usage: "Display the GOPATH for the present project",
Description: `Emits the GOPATH for the current project. Useful for
things like manually setting GOPATH: GOPATH=$(glide gopath)`,
Action: func(c *cli.Context) {
setupHandler(c, "gopath", cxt, router)
},
},
{
Name: "pin",
Usage: "Print a YAML file with all of the packages pinned to the current version",
Action: func(c *cli.Context) {
setupHandler(c, "pin", cxt, router)
},
},
{
Name: "rebuild",
Usage: "Rebuild ('go build') the dependencies",
Action: func(c *cli.Context) {
setupHandler(c, "rebuild", cxt, router)
},
},
{
Name: "status",
ShortName: "s",
Usage: "Display a status report",
Action: func(c *cli.Context) {
setupHandler(c, "status", cxt, router)
},
},
{
Name: "update",
ShortName: "up",
Usage: "Update existing packages",
Action: func(c *cli.Context) {
setupHandler(c, "update", cxt, router)
},
},
{
Name: "guess",
Usage: "Guess dependencies for existing source.",
Action: func(c *cli.Context) {
setupHandler(c, "guess", cxt, router)
},
},
}
}
func setupHandler(c *cli.Context, route string, cxt cookoo.Context, router *cookoo.Router) {
cxt.Put("q", c.GlobalBool("quiet"))
cxt.Put("yaml", c.GlobalString("yaml"))
if err := router.HandleRequest(route, cxt, false); err != nil {
fmt.Printf("Oops! %s\n", err)
os.Exit(1)
}
}
func routes(reg *cookoo.Registry, cxt cookoo.Context) {
reg.Route("@startup", "Parse args and send to the right subcommand.").
// TODO: Add setup for debug in addition to quiet.
Does(cmd.BeQuiet, "quiet").
Using("quiet").From("cxt:q")
reg.Route("@ready", "Prepare for glide commands.").
Does(cmd.ReadyToGlide, "ready").Using("filename").From("cxt:yaml").
Does(cmd.ParseYaml, "cfg").Using("filename").From("cxt:yaml")
reg.Route("into", "Creates a new Glide shell.").
Includes("@startup").
Does(cmd.AlreadyGliding, "isGliding").
Does(cmd.Into, "in").Using("into").From("cxt:toPath").
Using("into").WithDefault("").From("cxt:toPath").
Includes("@ready")
reg.Route("in", "Set GOPATH and supporting env vars.").
Includes("@startup").
Does(cmd.AlreadyGliding, "isGliding").
Includes("@ready").
Does(cmd.Into, "in").
Using("into").WithDefault("").From("cxt:toPath").
Using("conf").From("cxt:cfg")
reg.Route("gopath", "Return the GOPATH for the present project.").
Includes("@startup").
Does(cmd.In, "gopath")
reg.Route("install", "Install dependencies.").
Includes("@startup").
Does(cmd.InGopath, "pathIsRight").
Includes("@ready").
Does(cmd.Mkdir, "dir").Using("dir").WithDefault("_vendor").
Does(cmd.LinkPackage, "alias").
Does(cmd.GetImports, "dependencies").Using("conf").From("cxt:cfg").
Does(cmd.SetReference, "version").Using("conf").From("cxt:cfg").
Does(cmd.Rebuild, "rebuild").Using("conf").From("cxt:cfg")
reg.Route("update", "Update dependencies.").
Includes("@startup").
Includes("@ready").
Does(cmd.CowardMode, "_").
Does(cmd.UpdateImports, "dependencies").Using("conf").From("cxt:cfg").
Does(cmd.SetReference, "version").Using("conf").From("cxt:cfg").
Does(cmd.Rebuild, "rebuild").Using("conf").From("cxt:cfg")
reg.Route("rebuild", "Rebuild dependencies").
Includes("@startup").
Includes("@ready").
Does(cmd.CowardMode, "_").
Does(cmd.Rebuild, "rebuild").Using("conf").From("cxt:cfg")
reg.Route("pin", "Print a YAML file with all of the packages pinned to the current version.").
Includes("@startup").
Includes("@ready").
Does(cmd.UpdateReferences, "refs").Using("conf").From("cxt:cfg").
Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged")
reg.Route("godeps", "Read a Godeps file").
Includes("@startup").
Includes("@ready").
Does(cmd.Godeps, "godeps").
Does(cmd.AddDependencies, "addGodeps").
Using("dependencies").From("cxt:godeps").
Using("conf").From("cxt:cfg").
Does(cmd.GodepsGit, "godepsGit").
Does(cmd.AddDependencies, "addGodepsGit").
Using("dependencies").From("cxt:godepsGit").
Using("conf").From("cxt:cfg").
// Does(cmd.UpdateReferences, "refs").Using("conf").From("cxt:cfg").
Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged")
reg.Route("guess", "Guess dependencies").
Includes("@ready").
Does(cmd.GuessDeps, "")
reg.Route("create", "Initialize Glide").
Includes("@startup").
Does(cmd.InitGlide, "init").Using("filename").From("cxt:yaml")
reg.Route("status", "Status").
Includes("@startup").
Does(cmd.Status, "status")
reg.Route("@plugin", "Try to send to a plugin.").
Includes("@ready").
Does(cmd.DropToShell, "plugin").
Using("command").From("cxt:command")
}