func runCheck(cmd *Command, args []string) { // Check flags. num := checkFlags(cmd.Flags, config.AutoEnable.Check, args, printCheckPrompt) if num == -1 { return } args = args[num:] wd, _ := os.Getwd() // Guess import path. gopath := utils.GetBestMatchGOPATH(wd) + "/src/" if len(wd) <= len(gopath) { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["InvalidPath"])) return } importPath := wd[len(gopath):] imports, err := doc.CheckImports(wd+"/", importPath) if err != nil { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["CheckImports"]), err) return } if len(imports) == 0 { return } uninstallList := make([]string, 0) isInstalled := false // Check if dependencies have been installed. paths := utils.GetGOPATH() for _, v := range imports { // Make sure it doesn't belong to same project. if utils.GetProjectPath(v) != utils.GetProjectPath(importPath) { for _, p := range paths { if utils.IsExist(p + "/src/" + v + "/") { isInstalled = true break } } if !isInstalled { uninstallList = append(uninstallList, v) } } } // Check if need to install packages. if len(uninstallList) > 0 { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MissingImports"])) for _, v := range uninstallList { fmt.Printf("%s\n", v) } fmt.Printf(fmt.Sprintf("%s\n", promptMsg["ContinueDownload"])) var option string fmt.Fscan(os.Stdin, &option) if strings.ToLower(option) != "y" { os.Exit(0) } installGOPATH = utils.GetBestMatchGOPATH(appPath) fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH) // Generate temporary nodes. nodes := make([]*doc.Node, len(uninstallList)) for i := range nodes { nodes[i] = new(doc.Node) nodes[i].ImportPath = uninstallList[i] } // Download packages. downloadPackages(nodes) // Install packages all together. var cmdArgs []string cmdArgs = append(cmdArgs, "install") cmdArgs = append(cmdArgs, "<blank>") paths := utils.GetGOPATH() pkgPath := "/pkg/" + runtime.GOOS + "_" + runtime.GOARCH + "/" for _, k := range uninstallList { // Delete old packages. for _, p := range paths { os.RemoveAll(p + pkgPath + k + "/") os.Remove(p + pkgPath + k + ".a") } } for _, k := range uninstallList { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["InstallStatus"]), k) cmdArgs[1] = k executeCommand("go", cmdArgs) } // Generate configure file. } }
func runInstall(cmd *Command, args []string) { // Check flags. num := checkFlags(cmd.Flags, config.AutoEnable.Install, args, printInstallPrompt) if num == -1 { return } args = args[num:] // Check length of arguments. if len(args) < 1 { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["NoPackage"])) return } // Check version control tools. checkVCSTool() installGOPATH = utils.GetBestMatchGOPATH(appPath) fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH) // Generate temporary nodes. nodes := make([]*doc.Node, len(args)) for i := range nodes { nodes[i] = new(doc.Node) nodes[i].ImportPath = args[i] } // Download packages. downloadPackages(nodes) if !cmdInstall.Flags["-d"] && cmdInstall.Flags["-p"] { // Install packages all together. var cmdArgs []string cmdArgs = append(cmdArgs, "install") cmdArgs = append(cmdArgs, "<blank>") paths := utils.GetGOPATH() pkgPath := "/pkg/" + runtime.GOOS + "_" + runtime.GOARCH + "/" for k := range downloadCache { // Delete old packages. for _, p := range paths { os.RemoveAll(p + pkgPath + k + "/") os.Remove(p + pkgPath + k + ".a") } } for k := range downloadCache { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["InstallStatus"]), k) cmdArgs[1] = k executeCommand("go", cmdArgs) } // Save local nodes to file. fw, err := os.Create(appPath + "data/nodes.json") if err != nil { fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["OpenFile"]), err) return } defer fw.Close() fbytes, err := json.MarshalIndent(&localNodes, "", "\t") if err != nil { fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["ParseJSON"]), err) return } fw.Write(fbytes) } }