// removePackage removes package from local file system. func removePackage(node *doc.Node) (*doc.Node, []string) { // Find package in GOPATH. paths := utils.GetGOPATH() for _, p := range paths { absPath := p + "/src/" + utils.GetProjectPath(node.ImportPath) + "/" if utils.IsExist(absPath) { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["RemovePackage"]), node.ImportPath) // Remove files. os.RemoveAll(absPath) // Remove file in GOPATH/bin proName := utils.GetExecuteName(node.ImportPath) paths := utils.GetGOPATH() var gopath string for _, v := range paths { if utils.IsExist(v + "/bin/" + proName) { gopath = v // Don't need to find again. os.Remove(v + "/bin/" + proName) } } pkgList := []string{node.ImportPath} removePackageFiles(gopath, pkgList) return node, nil } } // Cannot find package. fmt.Printf(fmt.Sprintf("%s\n", promptMsg["PackageNotFound"]), node.ImportPath) return nil, nil }
// getAppPath returns application execute path for current process. func getAppPath() bool { // Look up executable in PATH variable. appPath, _ = exec.LookPath(path.Base(os.Args[0])) // Check if run under $GOPATH/bin if !utils.IsExist(appPath + "conf/") { paths := utils.GetGOPATH() for _, p := range paths { if utils.IsExist(p + "/src/github.com/GPMGo/gopm/") { appPath = p + "/src/github.com/GPMGo/gopm/" break } } } if len(appPath) == 0 { fmt.Printf("ERROR: getAppPath -> Unable to indicate current execute path.\n") return false } appPath = filepath.Dir(appPath) + "/" if runtime.GOOS == "windows" { // Replace all '\' to '/'. appPath = strings.Replace(appPath, "\\", "/", -1) } doc.SetAppConfig(appPath, config.AutoBackup) return true }
// checkIsExistWithVCS returns false if directory only has VCS folder, // or doesn't exist. func checkIsExistWithVCS(path string) bool { // Check if directory exist. if !utils.IsExist(path) { return false } // Check if only has VCS folder. dirs, err := utils.GetDirsInfo(path) if err != nil { fmt.Printf("checkIsExistWithVCS -> [ %s ]", err) return false } if len(dirs) > 1 { return true } else if len(dirs) == 0 { return false } switch dirs[0].Name() { case ".git", ".hg", ".svn": return false } return true }
func runBuild(cmd *Command, args []string) { // Check flags. num := checkFlags(cmd.Flags, config.AutoEnable.Build, args, printBuildPrompt) if num == -1 { return } args = args[num:] var cmdArgs []string cmdArgs = append(cmdArgs, "install") if cmdBuild.Flags["-v"] { cmdArgs = append(cmdArgs, "-v") } executeCommand("go", cmdArgs) // Find executable in GOPATH and copy to current directory. wd, _ := os.Getwd() proName := utils.GetExecuteName(wd) paths := utils.GetGOPATH() for _, v := range paths { if utils.IsExist(v + "/bin/" + proName) { if utils.IsExist(wd + "/" + proName) { err := os.Remove(wd + "/" + proName) if err != nil { fmt.Printf(fmt.Sprintf("ERROR: %s\n", promptMsg["RemoveFile"]), err) return } } err := os.Rename(v+"/bin/"+proName, wd+"/"+proName) if err == nil { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MovedFile"]), v, wd) // Check if need to run program. if cmdBuild.Flags["-r"] { cmdArgs = make([]string, 0) executeCommand(proName, cmdArgs) } return } fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MoveFile"]), v, wd) break } } }
// loadLocalNodes loads nodes information from local file system. func loadLocalNodes() bool { if !utils.IsExist(appPath + "data/nodes.json") { os.MkdirAll(appPath+"data/", os.ModePerm) } else { fr, err := os.Open(appPath + "data/nodes.json") if err != nil { fmt.Printf(fmt.Sprintf("ERROR: loadLocalNodes -> %s\n", promptMsg["LoadLocalData"]), err) return false } defer fr.Close() err = json.NewDecoder(fr).Decode(&localNodes) if err != nil && err != io.EOF { fmt.Printf(fmt.Sprintf("ERROR: loadLocalNodes -> %s\n", promptMsg["ParseJSON"]), err) return false } } return true }