Beispiel #1
0
// install the given version into the environment creating a Symlink to it
func (e *Environment) Install(ver string) error {
	if !cache.AlreadyCompiled(ver) {
		if err := cache.Compile(ver, false, false); err != nil {
			fmt.Println("while installing:", err)
			return err
		}
	}

	path := filepath.Join(cache.CacheDirectory(), ver)
	if _, err := os.Stat(path); err != nil {
		path = filepath.Join(cache.CacheDirectory(), fmt.Sprintf("go%s", ver))
	}

	link := func() error {
		return os.Symlink(path, filepath.Join(e.VenGO_PATH, "lib"))
	}

	if err := link(); err != nil {
		if os.IsExist(err) {
			os.Remove(filepath.Join(e.VenGO_PATH, "lib"))
			if err := link(); err != nil {
				fmt.Println("while creating symlink:", err)
				return err
			}
		} else {
			fmt.Println("while creating symlink:", err)
			return err
		}
	}

	return nil
}
Beispiel #2
0
// run the uninstall command
func runUninstall(cmd *Command, args ...string) {
	if len(args) == 0 {
		cmd.DisplayUsageAndExit()
	}
	version := args[0]
	activeEnv := os.Getenv("VENGO_ENV")
	if activeEnv != "" {
		if err := checkEnvironment(version, activeEnv); err != nil {
			fmt.Println("error:", err)
			fmt.Printf("%s: execute 'deactivate' before call this command\n", suggest)
			os.Exit(2)
		}
	}

	versionPath := filepath.Join(cache.CacheDirectory(), version)
	if _, err := os.Stat(versionPath); err != nil {
		log.Println(err)
		if os.IsNotExist(err) {
			fmt.Printf("%s is not a Go installed version...\n", version)
			fmt.Printf("%s: try with 'vengo list'\n", suggest)
			os.Exit(2)
		}
		log.Fatal(err)
	}
	err := os.RemoveAll(versionPath)
	if err == nil {
		fmt.Printf("%s has been uninstalled\n", utils.Ok(version))
	}
	log.Fatal(err)
}
Beispiel #3
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)
}
Beispiel #4
0
// generates the output for the list command
func (l *List) display(versions map[string][]string) (string, error) {
	output := []string{}
	if l.DisplayAs == Text {
		if l.ShowBoth || l.ShowInstalled {
			output = append(output, utils.Ok("Installed"))
			for _, v := range versions["installed"] {
				_, err := os.Stat(
					filepath.Join(cache.CacheDirectory(), v, ".vengo-manifest"))
				check := utils.Ok("✔")
				if err != nil {
					check = utils.Fail("✖")
				}
				output = append(output, fmt.Sprintf("    %s %s", v, check))
			}
		}
		if l.ShowBoth || l.ShowNotInstalled {
			output = append(output, utils.Ok("Available for Installation"))
			output = append(output, versions["available"]...)
		}
		return strings.Join(output, "\n"), nil
	}

	if l.DisplayAs == Json {
		jsonData := &BriefJSON{[]string{}, []string{}}
		if l.ShowBoth || l.ShowInstalled {
			for _, v := range versions["installed"] {
				v := strings.TrimLeft(v, "    ")
				jsonData.Installed = append(jsonData.Installed, v)
			}
		}
		if l.ShowBoth || l.ShowNotInstalled {
			for _, v := range versions["available"] {
				v := strings.TrimLeft(v, "    ")
				jsonData.Available = append(jsonData.Available, v)
			}
		}
		data, err := json.Marshal(jsonData)
		return string(data), err
	}

	return "", fmt.Errorf("List.DisplayAs is not set to a valid value!")
}
Beispiel #5
0
				os.RemoveAll(e.VenGO_PATH)
			})
		})

		Describe("Install", func() {
			It("Will create a symboolic link into VenGO_PATH", func() {
				Expect(cache.CacheDownloadGit("1.3.2")).To(Succeed())

				name := "goTest"
				prompt := "(gotest)"
				e := env.NewEnvironment(name, prompt)
				err := e.Generate()

				Expect(err).ToNot(HaveOccurred())
				Expect(e.Install("1.3.2")).To(Succeed())
				os.RemoveAll(filepath.Join(cache.CacheDirectory(), "go1.3.2"))
			})
		})
	}

	Describe("NewPackage", func() {
		It("Will return a configured package", func() {
			options := func(p *env.Package) {
				p.Name = "Test"
				p.Url = "github.com/VenGO/test"
				p.Installed = true
				p.Vcs = "git"
			}
			pkg := env.NewPackage(options)

			Expect(pkg).ToNot(BeNil())
Beispiel #6
0
// check if we are running on travis
// NOTE: this will return false positives in the home directory of anyone
// that is called travis and his home is "travis" or contains "travis", sorry
func runningOnTravis() bool {
	c := cache.CacheDirectory()
	return strings.Contains(c, "travis")
}
Beispiel #7
0
				re = regexp.MustCompile("/home/([a-z0-9]+)/.cache/VenGO")
			}

			if runtime.GOOS == "darwin" {
				re = regexp.MustCompile(
					"/Users/([a-zA-Z0-9]+)/Library/Caches/VenGO")
			}

			if runtime.GOOS == "windows" {
				re = regexp.MustCompile(
					"\\Users\\([a-zA-Z0-9]+)\\AppData\\VenGO")
			}
		})

		It("Should Match", func() {
			Expect(re.MatchString(cache.CacheDirectory())).To(BeTrue())
		})
	})

	Describe("Checksum return an error if version is not supported", func() {
		It("Should be empty string and formatted error", func() {
			sha1, err := cache.Checksum("1.0")

			Expect(sha1).To(BeEmpty())
			Expect(err).ToNot(BeNil())
		})
	})

	Describe("Checksum returns the right sha1 string", func() {
		Context("With version 1.2.2", func() {
			It("Should return 3ce0ac4db434fc1546fec074841ff40dc48c1167", func() {
Beispiel #8
0
		It("Create and return a configured list", func() {
			showBoth := func(l *commands.List) {
				l.ShowBoth = true
			}
			l := commands.NewList(showBoth)

			Expect(l).ToNot(BeNil())
			Expect(l.ShowBoth).To(BeTrue())
		})
	})

	Describe("List", func() {
		Describe("Run", func() {
			var renamed bool = false
			BeforeEach(func() {
				if _, err := os.Stat(filepath.Join(cache.CacheDirectory())); err == nil {
					rename := filepath.Join(cache.CacheDirectory(), "..", "Real-VenGO")
					Expect(os.Rename(cache.CacheDirectory(), rename)).To(Succeed())
					Expect(os.MkdirAll(cache.CacheDirectory(), 0755)).To(Succeed())
					renamed = true
				}
			})

			AfterEach(func() {
				if renamed {
					rename := filepath.Join(cache.CacheDirectory(), "..", "Real-VenGO")
					Expect(os.RemoveAll(cache.CacheDirectory())).To(Succeed())
					Expect(os.Rename(rename, cache.CacheDirectory())).To(Succeed())
				}
			})