// List func List(args []string, format string, all bool) error { dir := "." if len(args) > 0 { dir = args[0] } // scan the project directory provided pkgs, err := packages.Scan(dir) if err != nil { return err } // remove standard packages if !all { pkgs = packages.FilterStdPkgs(pkgs) } projectpath, err := packages.ImportPath(dir) if err != nil { return err } // filter out packages internal to the project pkgs = strutil.RemovePrefixInStringSlice(projectpath, pkgs) b, err := packages.Format(pkgs, format) if err != nil { return err } // print the results to screen fmt.Printf("%s\n", b) return nil }
// deptree downloads a dependency and the entire tree of dependencies/packages // that dependency requries as well. // // deptree takes a manifest as well as map of badimports to avoid as much // rework as possible. // // as well as an error, deptree returns the number of external package nodes // scanned in the dependecy tree excluding the root node/pkg. func deptree(pkg string, m *manifest.Manifest, bpkgs *badpkgs, level int, verbose bool, tree bool) (int, error) { // use the network to gather some metadata on this repo r, err := repo.Ping(pkg) if err != nil { if strings.Contains(err.Error(), "unrecognized import path") { bpkgs.append(pkg) if verbose { if tree { writeBlanks(level) } fmt.Printf("%s (bad ping)\n", pkg) } } return 0, err } // check if the repo is missing from the manifest file if !m.Contains(r.ImportPath) { if verbose { if tree { writeBlanks(level) } fmt.Printf("%s\n", r.ImportPath) } // download the repo rev, err := repo.Download(r, "vendor", "latest") if err != nil { return 0, err } // append the repo to the manifest file m.Append(r.ImportPath, rev) } pkgdeps, err := packages.Scan(filepath.Join("vendor", pkg)) if err != nil { if os.IsNotExist(err) { return 0, nil } return 0, err } // exclude standard packages pkgdeps = packages.FilterStdPkgs(pkgdeps) num := len(pkgdeps) level++ for _, pkgdep := range pkgdeps { if pkgdep != pkg && pkgdep != lastimport { lastimport = pkg n, err := deptree(pkgdep, m, bpkgs, level, verbose, tree) if err != nil { return num + n, err } // add num nodes scanned to the total tree n num += n } } return num, nil }