示例#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
// 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)
}