예제 #1
0
// getBundlePath returns the bundle path of a given kite.
// Example: "adsf-1.2.3" -> "~/.kd/kites/asdf-1.2.3.kite"
func getBundlePath(fullKiteName string) (string, error) {
	kiteHome, err := kitekey.KiteHome()
	if err != nil {
		return "", err
	}
	return filepath.Join(kiteHome, "kites", fullKiteName), nil
}
예제 #2
0
파일: list.go 프로젝트: GregWilson/kite
// getIntalledKites returns installed kites in .kd/kites folder.
// an empty argument returns all kites.
func getInstalledKites(kiteName string) ([]*InstalledKite, error) {
	kiteHome, err := kitekey.KiteHome()
	if err != nil {
		return nil, err
	}
	kitesPath := filepath.Join(kiteHome, "kites")

	domains, err := ioutil.ReadDir(kitesPath)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		}

		return nil, err
	}

	var installedKites []*InstalledKite // to be returned

	for _, domain := range domains {
		domainPath := filepath.Join(kitesPath, domain.Name())
		users, err := ioutil.ReadDir(domainPath)
		if err != nil {
			fmt.Println(err)
			continue
		}

		for _, user := range users {
			userPath := filepath.Join(domainPath, user.Name())
			repos, err := ioutil.ReadDir(userPath)
			if err != nil {
				fmt.Println(err)
				continue
			}

			for _, repo := range repos {
				repoPath := filepath.Join(userPath, repo.Name())
				versions, err := ioutil.ReadDir(repoPath)
				if err != nil {
					fmt.Println(err)
					continue
				}

				for _, version := range versions {
					versionPath := filepath.Join(repoPath, version.Name())
					binaryPath := filepath.Join(versionPath, "bin", strings.TrimSuffix(repo.Name(), ".kite"))
					_, err := os.Stat(binaryPath)
					if err != nil {
						fmt.Println(err)
						continue
					}

					installedKites = append(installedKites, NewInstalledKite(domain.Name(), user.Name(), repo.Name(), version.Name()))
				}
			}
		}
	}

	return installedKites, nil
}
예제 #3
0
파일: run.go 프로젝트: GregWilson/kite
func (c *Run) Run(args []string) int {

	// Parse kite name
	if len(args) == 0 {
		c.Ui.Output(c.Help())
		return 1
	}

	// User is allowed to enter kite name in these forms: "fs" or "github.com/koding/fs.kite/1.0.0"
	suppliedName := args[0]

	installedKites, err := getInstalledKites(suppliedName)
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	var matched []*InstalledKite

	for _, ik := range installedKites {
		if strings.TrimSuffix(ik.Repo, ".kite") == strings.TrimSuffix(suppliedName, ".kite") {
			matched = append(matched, ik)
		}
	}

	if len(matched) == 0 {
		for _, ik := range installedKites {
			if ik.String() == suppliedName {
				matched = append(matched, ik)
			}
		}
	}

	if len(matched) == 0 {
		c.Ui.Error("Kite not found")
		return 1
	}

	if len(matched) > 1 {
		c.Ui.Error("More than one version is installed. Please give a full kite name as: domain/user/repo/version")
		return 1
	}

	kiteHome, err := kitekey.KiteHome()
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	binPath := filepath.Join(kiteHome, "kites", matched[0].BinPath())
	err = syscall.Exec(binPath, args, os.Environ())
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	return 0
}
예제 #4
0
파일: install.go 프로젝트: GregWilson/kite
// installKite moves the .kite bundle into ~/kd/kites.
func installKite(bundlePath, repoName, version string) error {
	kiteHome, err := kitekey.KiteHome()
	if err != nil {
		return err
	}

	kitesPath := filepath.Join(kiteHome, "kites")
	repoPath := filepath.Join(kitesPath, repoName)
	versionPath := filepath.Join(repoPath, version)

	os.MkdirAll(repoPath, 0700)
	return os.Rename(bundlePath, versionPath)
}