Exemple #1
0
// 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
}
Exemple #2
0
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
		}
	}
}