Option to export the discovered YAML after glide up.
Also added --quick alias to up, and added file name output to
import commands.
diff --git a/cmd/flatten.go b/cmd/flatten.go
index a3450e1..74aff62 100644
--- a/cmd/flatten.go
+++ b/cmd/flatten.go
@@ -22,8 +22,12 @@
// Returns:
//
func Flatten(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
- packages := p.Get("packages", []string{}).([]string)
conf := p.Get("conf", &Config{}).(*Config)
+ skip := p.Get("skip", false).(bool)
+ if skip {
+ return conf, nil
+ }
+ packages := p.Get("packages", []string{}).([]string)
force := p.Get("force", true).(bool)
vend, _ := VendorPath(c)
@@ -43,10 +47,22 @@
f := &flattening{conf, vend, vend, deps, packages}
- a, err := recFlatten(f, force)
+ err := recFlatten(f, force)
flattenSetRefs(f)
Info("Project relies on %d dependencies.", len(deps))
- return a, err
+ exportFlattenedDeps(conf, deps)
+
+ return conf, err
+}
+
+func exportFlattenedDeps(conf *Config, in map[string]*Dependency) {
+ out := make([]*Dependency, len(in))
+ i := 0
+ for _, v := range in {
+ out[i] = v
+ i++
+ }
+ conf.Imports = out
}
type flattening struct {
@@ -62,10 +78,10 @@
}
// Hack: Cache record of updates so we don't have to keep doing git pulls.
-var flattenUpdateCache = map[string]bool{}
+var updateCache = map[string]bool{}
// refFlatten recursively flattens the vendor tree.
-func recFlatten(f *flattening, force bool) (interface{}, error) {
+func recFlatten(f *flattening, force bool) error {
Debug("---> Inspecting %s for changes (%d packages).\n", f.curr, len(f.scan))
for _, imp := range f.scan {
Debug("----> Scanning %s", imp)
@@ -96,8 +112,7 @@
}
}
- // Stopped: Need to recurse down the next level.
- return nil, nil
+ return nil
}
// flattenGlideUp does a glide update in the middle of a flatten operation.
@@ -110,7 +125,7 @@
for _, imp := range f.deps {
wd := path.Join(f.top, imp.Name)
if VcsExists(imp, wd) {
- if flattenUpdateCache[imp.Name] {
+ if updateCache[imp.Name] {
Debug("----> Already updated %s", imp.Name)
continue
}
@@ -120,7 +135,7 @@
Warn("Skipped update %s: %s\n", imp.Name, err)
continue
}
- flattenUpdateCache[imp.Name] = true
+ updateCache[imp.Name] = true
} else {
Debug("Importing %s to project %s\n", imp.Name, wd)
if err := VcsGet(imp, wd); err != nil {
@@ -216,7 +231,7 @@
// for dependencies. So generally it should be the last merge strategy
// that you try.
func mergeGuess(dir, pkg string, deps map[string]*Dependency) ([]string, bool) {
- Info("%s manages its own dependencies.", pkg)
+ Info("Scanning %s for dependencies.", pkg)
buildContext, err := GetBuildContext()
if err != nil {
Warn("Could not scan package %q: %s", pkg, err)
diff --git a/cmd/get_imports.go b/cmd/get_imports.go
index 405cdc5..c5dec3c 100644
--- a/cmd/get_imports.go
+++ b/cmd/get_imports.go
@@ -142,6 +142,12 @@
Debug("===> Skipping %q", dep.Name)
continue
}
+
+ // Hack: The updateCache global keeps us from re-updating the same
+ // dependencies when we're recursing. We cache here to prevent
+ // flattening from causing unnecessary updates.
+ updateCache[dep.Name] = true
+
if err := VcsUpdate(dep, cwd, force); err != nil {
Warn("Update failed for %s: %s\n", dep.Name, err)
}
diff --git a/cmd/yaml.go b/cmd/yaml.go
index f0fbbdf..b1a6e2c 100644
--- a/cmd/yaml.go
+++ b/cmd/yaml.go
@@ -63,6 +63,7 @@
// - filename (string): If set, the file will be opened and the content will be written to it.
func WriteYaml(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
top := p.Get("yaml.Node", yaml.Scalar("nothing to print")).(yaml.Node)
+ toStdout := p.Get("toStdout", true).(bool)
var out io.Writer
if nn, ok := p.Has("filename"); ok && len(nn.(string)) > 0 {
file, err := os.Create(nn.(string))
@@ -70,11 +71,12 @@
}
defer file.Close()
out = io.Writer(file)
- } else {
+ fmt.Fprint(out, yaml.Render(top))
+ } else if toStdout {
out = p.Get("out", os.Stdout).(io.Writer)
+ fmt.Fprint(out, yaml.Render(top))
}
-
- fmt.Fprint(out, yaml.Render(top))
+ // Otherwise we supress output.
return true, nil
}
diff --git a/glide.go b/glide.go
index f735b7a..06c37c6 100644
--- a/glide.go
+++ b/glide.go
@@ -171,7 +171,8 @@
os.Exit(1)
}
cxt.Put("packages", []string(c.Args()))
- cxt.Put("recursiveDependencies", !c.Bool("no-recursive"))
+ cxt.Put("skipFlatten", !c.Bool("no-recursive"))
+ // FIXME: Are these used anywhere?
if c.Bool("import") {
cxt.Put("importGodeps", true)
cxt.Put("importGPM", true)
@@ -187,21 +188,42 @@
{
Name: "godep",
Usage: "Import Godep's Godeps.json files and display the would-be yaml file",
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "file, f",
+ Usage: "Save all of the discovered dependencies to a Glide YAML file.",
+ },
+ },
Action: func(c *cli.Context) {
+ cxt.Put("toPath", c.String("file"))
setupHandler(c, "import godep", cxt, router)
},
},
{
Name: "gpm",
Usage: "Import GPM's Godeps and Godeps-Git files and display the would-be yaml file",
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "file, f",
+ Usage: "Save all of the discovered dependencies to a Glide YAML file.",
+ },
+ },
Action: func(c *cli.Context) {
+ cxt.Put("toPath", c.String("file"))
setupHandler(c, "import gpm", cxt, router)
},
},
{
Name: "gb",
Usage: "Import gb's manifest file and display the would-be yaml file",
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "file, f",
+ Usage: "Save all of the discovered dependencies to a Glide YAML file.",
+ },
+ },
Action: func(c *cli.Context) {
+ cxt.Put("toPath", c.String("file"))
setupHandler(c, "import gb", cxt, router)
},
},
@@ -285,6 +307,10 @@
dependencies, stored in your projects VCS repository, will be updated. This
works by removing the old package, checking out an the repo and setting the
version, and removing the VCS directory.
+
+ By default, packages that are discovered are considered transient, and are
+ not stored in the glide.yaml file. The --file=NAME.yaml flag allows you
+ to save the discovered dependencies to a YAML file.
`,
Flags: []cli.Flag{
cli.BoolFlag{
@@ -292,8 +318,8 @@
Usage: "Delete vendor packages not specified in config.",
},
cli.BoolFlag{
- Name: "no-recursive",
- Usage: "Disable updating dependencies' dependencies.",
+ Name: "no-recursive, quick",
+ Usage: "Disable updating dependencies' dependencies. Only update things in glide.yaml.",
},
cli.BoolFlag{
Name: "force",
@@ -303,12 +329,18 @@
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.",
},
+ cli.StringFlag{
+ Name: "file, f",
+ Usage: "Save all of the discovered dependencies to a Glide YAML file.",
+ },
},
Action: func(c *cli.Context) {
cxt.Put("deleteOptIn", c.Bool("delete"))
cxt.Put("forceUpdate", c.Bool("force"))
- cxt.Put("recursiveDependencies", !c.Bool("no-recursive"))
+ cxt.Put("skipFlatten", c.Bool("no-recursive"))
cxt.Put("deleteFlatten", c.Bool("delete-flatten"))
+ cxt.Put("toPath", c.String("file"))
+ cxt.Put("toStdout", false)
if c.Bool("import") {
cxt.Put("importGodeps", true)
cxt.Put("importGPM", true)
@@ -440,12 +472,18 @@
Using("force").From("cxt:forceUpdate").
Using("packages").From("cxt:packages").
Does(cmd.SetReference, "version").Using("conf").From("cxt:cfg").
- Does(cmd.Flatten, "flatten").Using("conf").From("cxt:cfg").
+ Does(cmd.Flatten, "flattened").Using("conf").From("cxt:cfg").
Using("packages").From("cxt:packages").
Using("force").From("cxt:forceUpdate").
+ Using("skip").From("cxt:skipFlatten").
Does(cmd.VendoredCleanUp, "_").
Using("conf").From("cxt:cfg").
- Using("update").From("cxt:updateVendoredDeps")
+ Using("update").From("cxt:updateVendoredDeps").
+ Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
+ Does(cmd.WriteYaml, "out").
+ Using("yaml.Node").From("cxt:merged").
+ Using("filename").From("cxt:toPath").
+ Using("toStdout").From("cxt:toStdout")
//Does(cmd.Rebuild, "rebuild").Using("conf").From("cxt:cfg")
@@ -477,7 +515,8 @@
Using("conf").From("cxt:cfg").
// Does(cmd.UpdateReferences, "refs").Using("conf").From("cxt:cfg").
Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
- Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged")
+ Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged").
+ Using("filename").From("cxt:toPath")
reg.Route("import godep", "Read a Godeps.json file").
Includes("@startup").
@@ -488,7 +527,8 @@
Using("conf").From("cxt:cfg").
// Does(cmd.UpdateReferences, "refs").Using("conf").From("cxt:cfg").
Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
- Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged")
+ Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged").
+ Using("filename").From("cxt:toPath")
reg.Route("import gb", "Read a vendor/manifest file").
Includes("@startup").
@@ -498,7 +538,8 @@
Using("dependencies").From("cxt:manifest").
Using("conf").From("cxt:cfg").
Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg").
- Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged")
+ Does(cmd.WriteYaml, "out").Using("yaml.Node").From("cxt:merged").
+ Using("filename").From("cxt:toPath")
reg.Route("guess", "Guess dependencies").
Includes("@ready").