// getDepList get list of dependencies in root path format and nature order. func getDepList(ctx *cli.Context, target, pkgPath, vendor string) ([]string, error) { vendorSrc := path.Join(vendor, "src") rootPath := doc.GetRootPath(target) // If work directory is not in GOPATH, then need to setup a vendor path. if !setting.HasGOPATHSetting || !strings.HasPrefix(pkgPath, setting.InstallGopath) { // Make link of self. log.Debug("Linking %s...", rootPath) from := pkgPath to := path.Join(vendorSrc, rootPath) if setting.Debug { log.Debug("Linking from %s to %s", from, to) } if err := autoLink(from, to); err != nil { return nil, err } } imports, err := doc.ListImports(target, rootPath, vendor, pkgPath, ctx.String("tags"), ctx.Bool("test")) if err != nil { return nil, err } list := make([]string, 0, len(imports)) for _, name := range imports { name = doc.GetRootPath(name) if !base.IsSliceContainsStr(list, name) { list = append(list, name) } } sort.Strings(list) return list, nil }
func getByGopmfile(ctx *cli.Context) error { // Make sure gopmfile exists and up-to-date. gf, target, err := parseGopmfile(setting.GOPMFILE) if err != nil { return err } imports, err := getDepList(ctx, target, setting.WorkDir, setting.DefaultVendor) if err != nil { return err } // Check if dependency has version. nodes := make([]*doc.Node, 0, len(imports)) for _, name := range imports { name = doc.GetRootPath(name) n := doc.NewNode(name, doc.BRANCH, "", "", !ctx.Bool("download")) // Check if user specified the version. if v := gf.MustValue("deps", name); len(v) > 0 { n.Type, n.Value, n.DownloadURL, err = validPkgInfo(v) n = doc.NewNode(name, n.Type, n.Value, n.DownloadURL, !ctx.Bool("download")) } nodes = append(nodes, n) } return getPackages(target, ctx, nodes) }