1
|
|
|
package action |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"github.com/Masterminds/glide/cache" |
5
|
|
|
"github.com/Masterminds/glide/cfg" |
6
|
|
|
"github.com/Masterminds/glide/msg" |
7
|
|
|
gpath "github.com/Masterminds/glide/path" |
8
|
|
|
"github.com/Masterminds/glide/repo" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
// Remove removes a dependncy from the configuration. |
12
|
|
|
func Remove(packages []string, inst *repo.Installer) { |
13
|
|
|
cache.SystemLock() |
14
|
|
|
base := gpath.Basepath() |
15
|
|
|
EnsureGopath() |
16
|
|
|
EnsureVendorDir() |
17
|
|
|
conf := EnsureConfig() |
18
|
|
|
glidefile, err := gpath.Glide() |
19
|
|
|
if err != nil { |
20
|
|
|
msg.Die("Could not find Glide file: %s", err) |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
msg.Info("Preparing to remove %d packages.", len(packages)) |
24
|
|
|
conf.Imports = rmDeps(packages, conf.Imports) |
25
|
|
|
conf.DevImports = rmDeps(packages, conf.DevImports) |
26
|
|
|
|
27
|
|
|
// Copy used to generate locks. |
28
|
|
|
confcopy := conf.Clone() |
29
|
|
|
|
30
|
|
|
//confcopy.Imports = inst.List(confcopy) |
31
|
|
|
|
32
|
|
|
if err := repo.SetReference(confcopy, inst.ResolveTest); err != nil { |
33
|
|
|
msg.Err("Failed to set references: %s", err) |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
err = inst.Export(confcopy) |
37
|
|
|
if err != nil { |
38
|
|
|
msg.Die("Unable to export dependencies to vendor directory: %s", err) |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Write glide.yaml |
42
|
|
|
if err := conf.WriteFile(glidefile); err != nil { |
43
|
|
|
msg.Die("Failed to write glide YAML file: %s", err) |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// Write glide lock |
47
|
|
|
writeLock(conf, confcopy, base) |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// rmDeps returns a list of dependencies that do not contain the given pkgs. |
51
|
|
|
// |
52
|
|
|
// It generates neither an error nor a warning for a pkg that does not exist |
53
|
|
|
// in the list of deps. |
54
|
|
|
func rmDeps(pkgs []string, deps []*cfg.Dependency) []*cfg.Dependency { |
55
|
|
|
res := []*cfg.Dependency{} |
56
|
|
|
for _, d := range deps { |
57
|
|
|
rem := false |
58
|
|
|
for _, p := range pkgs { |
59
|
|
|
if p == d.Name { |
60
|
|
|
rem = true |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
if !rem { |
64
|
|
|
res = append(res, d) |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
return res |
68
|
|
|
} |
69
|
|
|
|