示例#1
0
文件: mkenv.go 项目: jmartiuk5/VenGO
// implements the Runner interface creating the new virtual environment
func (m *Mkenv) Run() (string, error) {
	fmt.Fprint(cache.Output, "Checking installed Go versions... ")
	if err := m.checkInstalled(); err != nil {
		fmt.Fprintln(cache.Output, utils.Fail("✖"))
		return "", err
	}
	fmt.Fprintln(cache.Output, utils.Ok("✔"))

	newEnv := env.NewEnvironment(m.Name, m.Prompt)
	if newEnv.Exists() && !m.Force {
		suggest := fmt.Sprintf(
			"  %s: use --force to force reinstallation", utils.Ok("suggestion"))
		return "", fmt.Errorf("error: %s already exists\n%s", m.Name, suggest)
	}
	if err := newEnv.Generate(); err != nil {
		os.RemoveAll(filepath.Join(os.Getenv("VENGO_HOME"), m.Name))
		return "", err
	}
	if err := newEnv.Install(m.Version); err != nil {
		os.RemoveAll(filepath.Join(os.Getenv("VENGO_HOME"), m.Name))
		return "", err
	}

	return fmt.Sprintf(
		"%s", utils.Ok(fmt.Sprintf(
			"Go %s environment created using %s", m.Name, m.Version))), nil
}
示例#2
0
文件: export.go 项目: jmartiuk5/VenGO
// load environment using the activate environment script, return an error
// if the operation can't be completed
func (e *Export) LoadEnvironment() (*env.Environment, error) {
	readFile := func(filename string) ([]byte, error) {
		return ioutil.ReadFile(filename)
	}
	filenames := [2]string{
		filepath.Join(e.Environment, "bin", "activate"),
		filepath.Join(cache.VenGO_PATH, e.Environment, "bin", "activate"),
	}
	var err error
	var activateFile []byte
	for _, filename := range filenames {
		activateFile, err = readFile(filename)
		if err == nil {
			break
		}
	}
	if err != nil {
		return nil, err
	}
	byteLines := bytes.Split(activateFile, []byte("\n"))
	re := regexp.MustCompile(`"(.*?) `)
	prompt := strings.TrimRight(strings.TrimLeft(
		re.FindAllString(string(byteLines[86]), 1)[0], `"`), " ")
	environment := env.NewEnvironment(path.Base(e.Environment), prompt)
	return environment, nil
}
示例#3
0
	log.SetOutput(ioutil.Discard)

	BeforeSuite(func() {
		cache.VenGO_PATH = filepath.Join(cache.VenGO_PATH, "..", ".VenGOTest")
		os.MkdirAll(cache.VenGO_PATH, 0755)
	})

	AfterSuite(func() {
		os.RemoveAll(cache.VenGO_PATH)
	})

	Describe("NewEnvironment", func() {
		It("Return a configured Environment structure", func() {
			name, prompt := "goTest", "(goTest)"
			path := filepath.Join(cache.VenGO_PATH, name)
			e := env.NewEnvironment(name, prompt)
			Expect(e.Goroot).To(Equal(filepath.Join(path, "lib")))
			Expect(e.Gotooldir).To(Equal(filepath.Join(
				path, "lib", "pkg", "tool", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH))))
			Expect(e.Gopath).To(Equal(path))
			Expect(e.PS1).To(Equal(prompt))
			Expect(e.VenGO_PATH).To(Equal(path))
		})
	})

	if RunSlowTests {
		Describe("Generate", func() {
			It("Will generate a valid template file", func() {
				name := "goTest"
				prompt := "[{(goTest)}] "
				e := env.NewEnvironment(name, prompt)
示例#4
0
		})
	})

	Describe("LoadEnvironment", func() {
		var renamed bool = false
		envs_path := cache.ExpandUser(filepath.Join("~", ".VenGO"))
		BeforeEach(func() {
			os.Setenv("VENGO_HOME", "")
			if _, err := os.Stat(envs_path); err == nil {
				rename := filepath.Join(envs_path, "..", "Real.VenGO")
				Expect(os.Rename(envs_path, rename)).To(Succeed())
				Expect(os.MkdirAll(envs_path, 0755)).To(Succeed())
				renamed = true
			}

			e := env.NewEnvironment("goTest", "[{(goTest)}]")
			Expect(e.Generate()).To(Succeed())
		})

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

		It("Should return back a complete loaded environment", func() {
			options := func(e *commands.Export) {
				e.Environment = cache.ExpandUser("~/.VenGO/goTest")
			}