| 34 | } |
| 35 | |
| 36 | func (c *Run) Run(args []string) int { |
| 37 | |
| 38 | // Parse kite name |
| 39 | if len(args) == 0 { |
| 40 | c.Ui.Output(c.Help()) |
| 41 | return 1 |
| 42 | } |
| 43 | |
| 44 | // User is allowed to enter kite name in these forms: "fs" or "github.com/koding/fs.kite/1.0.0" |
| 45 | suppliedName := args[0] |
| 46 | |
| 47 | installedKites, err := getInstalledKites(suppliedName) |
| 48 | if err != nil { |
| 49 | c.Ui.Error(err.Error()) |
| 50 | return 1 |
| 51 | } |
| 52 | |
| 53 | var matched []*InstalledKite |
| 54 | |
| 55 | for _, ik := range installedKites { |
| 56 | if strings.TrimSuffix(ik.Repo, ".kite") == strings.TrimSuffix(suppliedName, ".kite") { |
| 57 | matched = append(matched, ik) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if len(matched) == 0 { |
| 62 | for _, ik := range installedKites { |
| 63 | if ik.String() == suppliedName { |
| 64 | matched = append(matched, ik) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if len(matched) == 0 { |
| 70 | c.Ui.Error("Kite not found") |
| 71 | return 1 |
| 72 | } |
| 73 | |
| 74 | if len(matched) > 1 { |
| 75 | c.Ui.Error("More than one version is installed. Please give a full kite name as: domain/user/repo/version") |
| 76 | return 1 |
| 77 | } |
| 78 | |
| 79 | kiteHome, err := kitekey.KiteHome() |
| 80 | if err != nil { |
| 81 | c.Ui.Error(err.Error()) |
| 82 | return 1 |
| 83 | } |
| 84 | |
| 85 | binPath := filepath.Join(kiteHome, "kites", matched[0].BinPath()) |
| 86 | err = syscall.Exec(binPath, args, os.Environ()) |
| 87 | if err != nil { |
| 88 | c.Ui.Error(err.Error()) |
| 89 | return 1 |
| 90 | } |
| 91 | |
| 92 | return 0 |
| 93 | } |