Trial run of `glide novendor`.
diff --git a/cmd/novendor.go b/cmd/novendor.go new file mode 100644 index 0000000..783f1d0 --- /dev/null +++ b/cmd/novendor.go
@@ -0,0 +1,75 @@ +package cmd + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/Masterminds/cookoo" +) + +// NoVendor takes a path and returns all subpaths that are not vendor directories. +// +// It is not recursive. +// +// If the given path is a file, it returns that path unaltered. +// +// If the given path is a directory, it scans all of the immediate children, +// and returns all of the go files and directories that are not vendor. +func NoVendor(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { + path := p.Get("path", ".").(string) + + return noVend(path) +} + +// Take a list of paths and print a single string with space-separated paths. +func PathString(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { + paths := p.Get("paths", []string{}).([]string) + s := strings.Join(paths, " ") + fmt.Println(s) + return nil, nil +} + +// noVend takes a directory and returns a list of Go-like files or directories, +// provided the directory is not a vendor directory. +func noVend(path string) ([]string, error) { + + info, err := os.Stat(path) + if err != nil { + return []string{}, err + } + + if !info.IsDir() { + return []string{path}, nil + } + + res := []string{} + f, err := os.Open(path) + if err != nil { + return res, err + } + + fis, err := f.Readdir(0) + if err != nil { + return res, err + } + + for _, fi := range fis { + full := filepath.Join(path, fi.Name()) + if fi.IsDir() && !isVend(fi) { + res = append(res, full) + } else if !fi.IsDir() && isGoish(fi) { + res = append(res, full) + } + } + return res, nil +} + +func isVend(fi os.FileInfo) bool { + return fi.Name() == "vendor" +} + +func isGoish(fi os.FileInfo) bool { + return filepath.Ext(fi.Name()) == ".go" +}
diff --git a/glide.go b/glide.go index 0f1dee5..d421168 100644 --- a/glide.go +++ b/glide.go
@@ -187,6 +187,20 @@ }, }, { + Name: "novendor", + ShortName: "nv", + Usage: "List all non-vendor directories and go files in a directory.", + Description: `Given a directory, list all the relevant Go files that are not vendored. + +Example: + + $ go test $(glide novendor) +`, + Action: func(c *cli.Context) { + setupHandler(c, "nv", cxt, router) + }, + }, + { Name: "pin", Usage: "Print a YAML file with all of the packages pinned to the current version", Description: `Begins with the current glide.yaml and sets an absolute ref @@ -404,6 +418,11 @@ Includes("@startup"). Does(cmd.Status, "status") + reg.Route("nv", "No Vendor"). + Includes("@startup"). + Does(cmd.NoVendor, "paths"). + Does(cmd.PathString, "out").Using("paths").From("cxt:paths") + reg.Route("status", "Status"). Includes("@startup"). Does(cmd.Status, "status")