forked from Masterminds/glide
/
init_glide.go
59 lines (50 loc) · 1.52 KB
/
init_glide.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
package cmd
import (
"fmt"
"os"
"github.com/Masterminds/cookoo"
)
var yamlTpl = `# Glide YAML configuration file
# Set this to your fully qualified package name, e.g.
# github.com/Masterminds/foo. This should be the
# top level package.
package: %s
# Declare your project's dependencies.
import:
# Fetch package similar to 'go get':
#- package: github.com/Masterminds/cookoo
# Get and manage a package with Git:
#- package: github.com/Masterminds/cookoo
# # The repository URL
# repo: git@github.com:Masterminds/cookoo.git
# # A tag, branch, or SHA
# ref: 1.1.0
# # the VCS type (compare to bzr, hg, svn). You should
# # set this if you know it.
# vcs: git
`
// InitGlide initializes a new Glide project.
//
// Among other things, it creates a default glide.yaml.
//
// Params:
// - filename (string): The name of the glide YAML file. Default is glide.yaml.
// - project (string): The name of the project. Default is 'main'.
func InitGlide(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
fname := p.Get("filename", "glide.yaml").(string)
pname := p.Get("project", "main").(string)
vdir := c.Get("VendorDir", "vendor").(string)
if _, err := os.Stat(fname); err == nil {
cwd, _ := os.Getwd()
return false, fmt.Errorf("Cowardly refusing to overwrite %s in %s", fname, cwd)
}
f, err := os.Create(fname)
if err != nil {
return false, err
}
fmt.Fprintf(f, yamlTpl, pname)
f.Close()
os.MkdirAll(vdir, 0755)
Info("Initialized. You can now edit '%s'\n", fname)
return true, nil
}