forked from Masterminds/glide
/
vendor_path.go
44 lines (34 loc) · 847 Bytes
/
vendor_path.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
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/Masterminds/cookoo"
)
// Return the path to the vendor directory.
func VendorPath(c cookoo.Context) (string, error) {
vendor := c.Get("VendorDir", "vendor").(string)
filename := c.Get("yaml", "glide.yaml").(string)
cwd, err := os.Getwd()
if err != nil {
return "", err
}
// Find the directory that contains glide.yaml
yamldir, err := glideWD(cwd, filename)
if err != nil {
return cwd, err
}
gopath := filepath.Join(yamldir, vendor)
return gopath, nil
}
func glideWD(dir, filename string) (string, error) {
fullpath := filepath.Join(dir, filename)
if _, err := os.Stat(fullpath); err == nil {
return dir, nil
}
base := filepath.Dir(dir)
if base == dir {
return "", fmt.Errorf("Cannot resolve parent of %s", base)
}
return glideWD(base, filename)
}