In several places, add support for specifying package.
This addresses:
- Issue #92: glide update [repo [repo [repo [...]]]]
- Issue #96: streamlines a bit from previous commits
- Issue #101: do not do redundant work on `glide get foo`
- Extended that to do the same for `glide update`
- Set the foundation for #85 by adding package list to UpdateReferences.
However, there's more work to do on #85, including some that will
break backward compat.
diff --git a/cmd/get_imports.go b/cmd/get_imports.go
index e977266..da4ad69 100644
--- a/cmd/get_imports.go
+++ b/cmd/get_imports.go
@@ -95,6 +95,8 @@
//
// Returns:
// - *Dependency: A dependency describing this package.
+//
+// DEPRECATED: This will be removed in the future. Use `GetAll` instead.
func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
name := p.Get("package", "").(string)
cfg := p.Get("conf", nil).(*Config)
@@ -161,9 +163,19 @@
}
// UpdateImports iterates over the imported packages and updates them.
+//
+// Params:
+//
+// - force (bool): force packages to update (default false)
+// - conf (*Config): The configuration
+// - packages([]string): The packages to update. Default is all.
func UpdateImports(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
cfg := p.Get("conf", nil).(*Config)
force := p.Get("force", true).(bool)
+ plist := p.Get("packages", []string{}).([]string)
+ pkgs := list2map(plist)
+ restrict := len(pkgs) > 0
+
cwd, err := VendorPath(c)
if err != nil {
return false, err
@@ -175,6 +187,10 @@
}
for _, dep := range cfg.Imports {
+ if restrict && !pkgs[dep.Name] {
+ Debug("===> Skipping %q", dep.Name)
+ continue
+ }
if err := VcsUpdate(dep, cwd, force); err != nil {
Warn("Update failed for %s: %s\n", dep.Name, err)
}
diff --git a/cmd/recursive_glide.go b/cmd/recursive_glide.go
index 83ea5d6..717249e 100644
--- a/cmd/recursive_glide.go
+++ b/cmd/recursive_glide.go
@@ -10,13 +10,28 @@
)
// Recurse does glide installs on dependent packages.
+//
// Recurse looks in all known packages for a glide.yaml files and installs for
// each one it finds.
+//
+// The packages scanned can be restricted (at the top level) by providing
+// a list of packages to scan in the `packages` param.
+//
+// Params:
+// - enable (bool)
+// - importGodeps (bool)
+// - importGPM (bool)
+// - importGb (bool)
+// - deleteFlatten (bool)
+// - force (bool)
+// - packages ([]string): Packages to recurse through. If empty, does all of them.
func Recurse(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
if !p.Get("enable", true).(bool) {
return nil, nil
}
force := p.Get("force", true).(bool)
+ plist := p.Get("packages", []string{}).([]string)
+ pkgs := list2map(plist)
godeps, gpm, gb, deleteFlatten := false, false, false, false
if g, ok := p.Has("importGodeps"); ok {
@@ -40,10 +55,10 @@
conf := p.Get("conf", &Config{}).(*Config)
vend, _ := VendorPath(c)
- return recDepResolve(conf, vend, godeps, gpm, gb, force, deleteFlatten)
+ return recDepResolve(conf, pkgs, vend, godeps, gpm, gb, force, deleteFlatten)
}
-func recDepResolve(conf *Config, vend string, godeps, gpm, gb, force, deleteFlatten bool) (interface{}, error) {
+func recDepResolve(conf *Config, filter map[string]bool, vend string, godeps, gpm, gb, force, deleteFlatten bool) (interface{}, error) {
Info("Inspecting %s.\n", vend)
@@ -51,8 +66,14 @@
Info("No imports.\n")
}
+ restrict := len(filter) > 0
+
// Look in each package to see whether it has a glide.yaml, and no vendor/
for _, imp := range conf.Imports {
+ if restrict && !filter[imp.Name] {
+ Debug("===> Skipping %q", imp.Name)
+ continue
+ }
if imp.Flattened == true {
continue
}
@@ -161,7 +182,9 @@
//recDepResolve(conf, path.Join(wd, "vendor"))
}
- recDepResolve(conf, path.Join(base, "vendor"), godep, gpm, gb, force, deleteFlatten)
+ // We only filter at the top level.
+ e := map[string]bool{}
+ recDepResolve(conf, e, path.Join(base, "vendor"), godep, gpm, gb, force, deleteFlatten)
return nil
}
diff --git a/cmd/update_references.go b/cmd/update_references.go
index 2ad8f27..5536e64 100644
--- a/cmd/update_references.go
+++ b/cmd/update_references.go
@@ -5,8 +5,20 @@
)
// UpdateReferences updates the revision numbers on all of the imports.
+//
+// If a `packages` list is supplied, only the given base packages will
+// be updated.
+//
+// Params:
+// - conf (*Config): Configuration
+// - packages ([]string): A list of packages to update. Default is all packages.
func UpdateReferences(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
cfg := p.Get("conf", &Config{}).(*Config)
+ plist := p.Get("packages", []string{}).([]string)
+
+ pkgs := list2map(plist)
+ restrict := len(pkgs) > 0
+
cwd, err := VendorPath(c)
if err != nil {
return false, err
@@ -17,6 +29,10 @@
}
for _, imp := range cfg.Imports {
+ if restrict && !pkgs[imp.Name] {
+ Debug("===> Skipping %q", imp.Name)
+ continue
+ }
commit, err := VcsLastCommit(imp, cwd)
if err != nil {
Warn("Could not get commit on %s: %s", imp.Name, err)
@@ -26,3 +42,13 @@
return cfg, nil
}
+
+// list2map takes a list of packages names and creates a map of normalized names.
+func list2map(in []string) map[string]bool {
+ out := make(map[string]bool, len(in))
+ for _, v := range in {
+ v, _ := NormalizeName(v)
+ out[v] = true
+ }
+ return out
+}
diff --git a/glide.go b/glide.go
index 00eb8a5..a71c5b5 100644
--- a/glide.go
+++ b/glide.go
@@ -323,6 +323,8 @@
cxt.Put("importGb", true)
}
cxt.Put("updateVendoredDeps", c.Bool("update-vendored"))
+
+ cxt.Put("packages", []string(c.Args()))
setupHandler(c, "update", cxt, router)
},
},
@@ -420,6 +422,7 @@
Using("importGPM").From("cxt:importGPM").
Using("importGb").From("cxt:importGb").
Using("force").From("cxt:forceUpdate").WithDefault(false).
+ Using("packages").From("cxt:packages").
Does(cmd.WriteYaml, "out").
Using("yaml.Node").From("cxt:merged").
Using("filename").WithDefault("glide.yaml").From("cxt:yaml")
@@ -445,6 +448,7 @@
Does(cmd.UpdateImports, "dependencies").
Using("conf").From("cxt:cfg").
Using("force").From("cxt:forceUpdate").
+ Using("packages").From("cxt:packages").
Does(cmd.SetReference, "version").Using("conf").From("cxt:cfg").
Does(cmd.Recurse, "recurse").Using("conf").From("cxt:cfg").
Using("deleteFlatten").From("cxt:deleteFlatten").
@@ -453,6 +457,7 @@
Using("importGb").From("cxt:importGb").
Using("enable").From("cxt:recursiveDependencies").
Using("force").From("cxt:forceUpdate").
+ Using("packages").From("cxt:packages").
Does(cmd.VendoredCleanUp, "_").
Using("conf").From("cxt:cfg").
Using("update").From("cxt:updateVendoredDeps")