Exemplo n.º 1
0
func getByPath(ctx *cli.Context) {
	nodes := make([]*doc.Node, 0, len(ctx.Args()))
	for _, info := range ctx.Args() {
		pkgPath := info
		node := doc.NewNode(pkgPath, pkgPath, doc.BRANCH, "", true)

		if i := strings.Index(info, "@"); i > -1 {
			pkgPath = info[:i]
			tp, ver := validPath(info[i+1:])
			node = doc.NewNode(pkgPath, pkgPath, tp, ver, true)
		}

		// Check package name.
		if !strings.Contains(pkgPath, "/") {
			pkgPath = doc.GetPkgFullPath(pkgPath)
		}

		nodes = append(nodes, node)
	}

	downloadPackages(ctx, nodes)
	doc.SaveLocalNodes()

	log.Log("%d package(s) downloaded, %d failed", downloadCount, failConut)
}
Exemplo n.º 2
0
func getByGopmfile(ctx *cli.Context) {
	// Check if gopmfile exists and generate one if not.
	if !com.IsFile(".gopmfile") {
		runGen(ctx)
	}
	gf := doc.NewGopmfile(".")

	targetPath := parseTarget(gf.MustValue("target", "path"))
	// Get dependencies.
	imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example"))

	nodes := make([]*doc.Node, 0, len(imports))
	for _, p := range imports {
		p = doc.GetProjectPath(p)
		// Skip subpackage(s) of current project.
		if isSubpackage(p, targetPath) {
			continue
		}
		node := doc.NewNode(p, p, doc.BRANCH, "", true)

		// Check if user specified the version.
		if v, err := gf.GetValue("deps", p); err == nil && len(v) > 0 {
			node.Type, node.Value = validPath(v)
		}
		nodes = append(nodes, node)
	}

	downloadPackages(ctx, nodes)
	doc.SaveLocalNodes()

	log.Log("%d package(s) downloaded, %d failed", downloadCount, failConut)
}