Ejemplo n.º 1
0
// run the migrate command
func runMigrate(cmd *Command, args ...string) {
	if len(args) < 2 {
		cmd.DisplayUsageAndExit()
	}
	environName := args[0]
	goVersion := args[1]
	if os.Getenv("VENGO_ENV") == environName {
		fmt.Println(
			"error:", fmt.Sprintf("%s is currently in use as the active environment"))
		fmt.Printf("%s: execute 'deactivate' before call this command\n", suggest)
		os.Exit(2)
	}
	envPath := filepath.Join(os.Getenv("VENGO_HOME"), environName)
	if _, err := os.Stat(envPath); err != nil {
		fmt.Printf("%s is no a VenGO environment...\n", environName)
		fmt.Println(err)
		os.Exit(2)
	}
	fmt.Print("Checking installed Go versions...")
	if !env.LookupInstalledVersion(goVersion) {
		fmt.Println(utils.Fail("✖"))
		fmt.Println(fmt.Sprintf(
			"sorry vengo can't perform the operation because %s is %s",
			goVersion, utils.Fail("not installed")))
		fmt.Printf("%s: run 'vengo install %s'\n", suggest, goVersion)
		os.Exit(2)
	}
	fmt.Println(utils.Ok("✔"))

	library := filepath.Join(envPath, "lib")
	installed, _ := os.Readlink(library)
	if installed == goVersion {
		fmt.Printf("%s in use Go version is already %s, skipping...", environName, installed)
		os.Exit(0)
	}
	fmt.Printf("unlinking previous %s Go version from %s...", installed, environName)
	if err := os.Remove(library); err != nil {
		fmt.Println(utils.Fail("✖"))
		fmt.Println(err)
		os.Exit(2)
	}
	fmt.Println(utils.Ok("✔"))
	fmt.Printf("Linking Go version %s...", goVersion)
	path := filepath.Join(cache.CacheDirectory(), goVersion)
	err := os.Symlink(path, filepath.Join(envPath, "lib"))
	if err != nil {
		fmt.Println(utils.Fail("✖"))
		fmt.Println(err)
		os.Exit(2)
	}
	fmt.Println(utils.Ok("✔"))
	fmt.Println("Done. You may want to run 'go build -a ./... in $GOPATH")
	os.Exit(0)
}
Ejemplo n.º 2
0
// check if the Go version used to generate the virtual environment is
// installed or not, if is not, return a NotIntalled error type
func (m *Mkenv) checkInstalled() error {
	if !env.LookupInstalledVersion(m.Version) {
		return ErrNotInstalled
	}
	return nil
}