-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
43 lines (37 loc) · 940 Bytes
/
get.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
package main
import (
"context"
"strings"
)
// Get gets list of specified packages with its dependencies.
func Get(ctx context.Context, pkgs []string, update, updateDeps, constraint, verbose bool) ([]string, error) {
var newPkgs []string
for _, pkg := range pkgs {
var isLocal bool
if strings.HasPrefix(pkg, "file://") {
isLocal = true
pkg = strings.TrimPrefix(pkg, "file://")
}
var version string
if i := strings.Index(pkg, "@"); i != -1 && i != len(pkg)-1 {
pkg, version = pkg[:i], pkg[i+1:]
if constraint {
manifest.Constraints[pkg] = version
}
}
opts := ImportOptions{
FetchAll: pkg == getPkgRoot(pkg),
Local: isLocal,
Update: update,
UpdateDeps: updateDeps,
Version: version,
}
if err := importPackage(ctx, pkg, opts, verbose); err != nil {
return newPkgs, err
}
}
if err := saveManifest(); err != nil {
return newPkgs, err
}
return newPkgs, nil
}