Пример #1
0
// downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only.
func downloadPackages(nodes []*doc.Node) {
	// Check all packages, they may be bundles, snapshots or raw packages path.
	for _, n := range nodes {
		// Check if it is a bundle or snapshot.
		switch {
		case strings.HasSuffix(n.ImportPath, ".b"):
			l := len(n.ImportPath)
			// Check local bundles.
			bnodes := checkLocalBundles(n.ImportPath[:l-2])
			if len(bnodes) > 0 {
				// Check with users if continue.
				fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])
				for _, bn := range bnodes {
					fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value)
				}
				fmt.Printf(fmt.Sprintf("%s\n", promptMsg["ContinueDownload"]))
				var option string
				fmt.Fscan(os.Stdin, &option)
				if strings.ToLower(option) != "y" {
					os.Exit(0)
				}
				downloadPackages(bnodes)
			} else {
				// Check from server.
				// TODO: api.GetBundleInfo()
				fmt.Println("Unable to find bundle, and we cannot check with server right now.")
			}
		case strings.HasSuffix(n.ImportPath, ".s"):
			// TODO: api.GetSnapshotInfo()
		case utils.IsValidRemotePath(n.ImportPath):
			if !downloadCache[n.ImportPath] {
				// Download package.
				node, imports := downloadPackage(n)
				if len(imports) > 0 {
					// Need to download dependencies.
					// Generate temporary nodes.
					nodes := make([]*doc.Node, len(imports))
					for i := range nodes {
						nodes[i] = new(doc.Node)
						nodes[i].ImportPath = imports[i]
					}
					downloadPackages(nodes)
				}

				// Only save package information with specific commit.
				if node != nil {
					// Save record in local nodes.
					saveNode(node)
				}
			} else {
				fmt.Printf(fmt.Sprintf("%s\n", promptMsg["SkipDownloaded"]), n.ImportPath)
			}
		default:
			// Invalid import path.
			fmt.Printf(fmt.Sprintf("%s\n", promptMsg["SkipInvalidPath"]), n.ImportPath)
		}
	}
}
Пример #2
0
// removePackages removes packages from local file system.
func removePackages(nodes []*doc.Node) {
	// Check all packages, they may be bundles, snapshots or raw packages path.
	for _, n := range nodes {
		// Check if it is a bundle or snapshot.
		switch {
		case strings.HasSuffix(n.ImportPath, ".b"):
			l := len(n.ImportPath)
			// Check local bundles.
			bnodes := checkLocalBundles(n.ImportPath[:l-2])
			if len(bnodes) > 0 {
				// Check with users if continue.
				fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])
				for _, bn := range bnodes {
					fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value)
				}
				fmt.Printf(fmt.Sprintf("%s\n", promptMsg["ContinueRemove"]))
				var option string
				fmt.Fscan(os.Stdin, &option)
				if strings.ToLower(option) != "y" {
					os.Exit(0)
				}
				removePackages(bnodes)
			} else {
				// Check from server.
				// TODO: api.GetBundleInfo()
				fmt.Println("Unable to find bundle, and we cannot check with server right now.")
			}
		case strings.HasSuffix(n.ImportPath, ".s"):
		case utils.IsValidRemotePath(n.ImportPath):
			if !removeCache[n.ImportPath] {
				// Remove package.
				node, imports := removePackage(n)
				if len(imports) > 0 {
					fmt.Println("Check denpendencies for removing package has not been supported.")
				}

				// Remove record in local nodes.
				if node != nil {
					removeNode(node)
				}
			}
		default:
			// Invalid import path.
			fmt.Printf(fmt.Sprintf("%s\n", promptMsg["SkipInvalidPath"]), n.ImportPath)
		}
	}
}