Added `glide list`.
diff --git a/cmd/tree.go b/cmd/tree.go
index 5061bb9..885f34a 100644
--- a/cmd/tree.go
+++ b/cmd/tree.go
@@ -6,6 +6,7 @@
"go/build"
"os"
"path/filepath"
+ "sort"
"strings"
"github.com/Masterminds/cookoo"
@@ -29,32 +30,68 @@
}
fmt.Println(myName)
-
- // Start with *.go
- // Do a breadth-first search of subdirectories, excluding _*, .*, testdata,
- // and vendor.
- /*
- deps := walkDeps(basedir, myName)
- for _, name := range deps {
- found := findPkg(name, basedir)
- msg := found.Path
- if found.PType == ptypeUnknown {
- msg = "glide get " + found.Name
- }
- if !showcore && found.PType == ptypeGoroot {
- continue
- }
- fmt.Printf("\t%s\t(%s)\n", found.Name, msg)
- }
- */
displayTree(basedir, myName, 1, showcore)
-
- // Now look up all of the external dependencies.
-
- // Make it pretty.
return nil, nil
}
+// ListDeps lists all of the dependencies of the current project.
+//
+// Params:
+//
+// Returns:
+//
+func ListDeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
+ basedir := p.Get("dir", ".").(string)
+ myName := guessPackageName(basedir)
+
+ var err error
+ basedir, err = filepath.Abs(basedir)
+ if err != nil {
+ return nil, err
+ }
+
+ direct := map[string]bool{}
+ d := walkDeps(basedir, myName)
+ for _, i := range d {
+ listDeps(direct, i, basedir)
+ }
+
+ sortable := make([]string, len(direct))
+ i := 0
+ for k, _ := range direct {
+ sortable[i] = k
+ i++
+ }
+
+ sort.Strings(sortable)
+
+ for _, k := range sortable {
+ dec := "no"
+ if direct[k] {
+ dec = "yes"
+ }
+ fmt.Printf("%s (Present: %s)\n", k, dec)
+ }
+
+ return nil, nil
+}
+
+func listDeps(info map[string]bool, name, path string) {
+ found := findPkg(name, path)
+ switch found.PType {
+ case ptypeUnknown:
+ info[name] = false
+ break
+ case ptypeGoroot:
+ break
+ default:
+ info[name] = true
+ for _, i := range walkDeps(found.Path, found.Name) {
+ listDeps(info, i, found.Path)
+ }
+ }
+}
+
func displayTree(basedir, myName string, level int, core bool) {
deps := walkDeps(basedir, myName)
for _, name := range deps {
diff --git a/glide.go b/glide.go
index 1daf147..ce59609 100644
--- a/glide.go
+++ b/glide.go
@@ -321,6 +321,13 @@
},
},
{
+ Name: "list",
+ Usage: "List prints all dependencies that Glide could discover.",
+ Action: func(c *cli.Context) {
+ setupHandler(c, "list", cxt, router)
+ },
+ },
+ {
Name: "guess",
Usage: "Guess dependencies for existing source.",
Description: `This looks through existing source and dependencies,
@@ -488,6 +495,11 @@
Includes("@ready").
Does(cmd.Tree, "tree").
Using("conf").From("cxt:cfg")
+ reg.Route("list", "Print a dependency graph.").
+ Includes("@startup").
+ Includes("@ready").
+ Does(cmd.ListDeps, "list").
+ Using("conf").From("cxt:cfg")
reg.Route("nv", "No Vendor").
Includes("@startup").