pluginInstall clona, compila e instala um plugin a partir de uma URL git.
(args []string)
| 210 | |
| 211 | // pluginInstall clona, compila e instala um plugin a partir de uma URL git. |
| 212 | func (ch *CommandHandler) pluginInstall(args []string) { |
| 213 | pluginManager := ch.cli.pluginManager |
| 214 | if len(args) < 3 { |
| 215 | fmt.Println(i18n.T("plugin.install.usage")) |
| 216 | return |
| 217 | } |
| 218 | rawURL := args[2] |
| 219 | |
| 220 | // Parse the URL: detect GitHub/GitLab tree URLs and extract repo, branch, subdir. |
| 221 | cloneURL, branch, subDir := parseGitURL(rawURL) |
| 222 | |
| 223 | // AVISO DE SEGURANÆA |
| 224 | fmt.Println(colorize(i18n.T("plugin.install.security_warning"), ColorYellow)) |
| 225 | |
| 226 | if runtime.GOOS != "windows" { |
| 227 | cmd := exec.Command("stty", "sane") |
| 228 | cmd.Stdin = os.Stdin |
| 229 | _ = cmd.Run() |
| 230 | } |
| 231 | |
| 232 | fmt.Print(i18n.T("plugin.install.confirm", rawURL)) |
| 233 | reader := bufio.NewReader(os.Stdin) |
| 234 | confirm, _ := reader.ReadString('\n') |
| 235 | if strings.ToLower(strings.TrimSpace(confirm)) != "s" { |
| 236 | fmt.Println(i18n.T("plugin.install.canceled")) |
| 237 | return |
| 238 | } |
| 239 | |
| 240 | fmt.Println(i18n.T("plugin.install.installing", rawURL)) |
| 241 | |
| 242 | tempDir, err := os.MkdirTemp("", "chatcli-plugin-") |
| 243 | if err != nil { |
| 244 | fmt.Println(i18n.T("plugin.install.error.tempdir", err)) |
| 245 | return |
| 246 | } |
| 247 | defer func() { _ = os.RemoveAll(tempDir) }() |
| 248 | |
| 249 | // Build git clone args: use --branch if we parsed one from the URL. |
| 250 | cloneArgs := []string{"clone", "--depth=1"} |
| 251 | if branch != "" { |
| 252 | cloneArgs = append(cloneArgs, "--branch", branch) |
| 253 | } |
| 254 | cloneArgs = append(cloneArgs, cloneURL, tempDir) |
| 255 | |
| 256 | cloneCmd := exec.Command("git", cloneArgs...) |
| 257 | if output, err := cloneCmd.CombinedOutput(); err != nil { |
| 258 | fmt.Println(i18n.T("plugin.install.error.clone", err)) |
| 259 | fmt.Println(string(output)) |
| 260 | return |
| 261 | } |
| 262 | |
| 263 | // Determine the build directory (repo root or subdirectory). |
| 264 | buildDir := tempDir |
| 265 | if subDir != "" { |
| 266 | buildDir = filepath.Join(tempDir, subDir) |
| 267 | if info, err := os.Stat(buildDir); err != nil || !info.IsDir() { |
| 268 | fmt.Println(i18n.T("plugin.install.error.build", |
| 269 | fmt.Errorf("subdirectory '%s' not found in repository", subDir), "")) |
no test coverage detected