handleDelete deleta um contexto permanentemente
(args []string)
| 295 | |
| 296 | // handleDelete deleta um contexto permanentemente |
| 297 | func (h *ContextHandler) handleDelete(args []string) error { |
| 298 | if len(args) < 1 { |
| 299 | return fmt.Errorf("%s", i18n.T("context.delete.usage")) |
| 300 | } |
| 301 | |
| 302 | contextName := args[0] |
| 303 | |
| 304 | // Buscar contexto por nome |
| 305 | ctx, err := h.manager.GetContextByName(contextName) |
| 306 | if err != nil { |
| 307 | return fmt.Errorf("%s", i18n.T("context.delete.error.not_found", contextName)) |
| 308 | } |
| 309 | |
| 310 | fmt.Printf("%s", i18n.T("context.delete.confirm", ctx.Name)) |
| 311 | |
| 312 | // Restaurar terminal antes de ler input |
| 313 | if runtime.GOOS != "windows" { |
| 314 | cmd := exec.Command("stty", "sane") |
| 315 | cmd.Stdin = os.Stdin |
| 316 | _ = cmd.Run() |
| 317 | } |
| 318 | |
| 319 | reader := bufio.NewReader(os.Stdin) |
| 320 | response, err := reader.ReadString('\n') |
| 321 | if err != nil { |
| 322 | return fmt.Errorf("%s: %w", i18n.T("ctx.cmd.read_response_error"), err) |
| 323 | } |
| 324 | |
| 325 | if strings.ToLower(strings.TrimSpace(response)) != "s" && |
| 326 | strings.ToLower(strings.TrimSpace(response)) != "y" { |
| 327 | fmt.Println(i18n.T("context.delete.canceled")) |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | // Deletar |
| 332 | if err := h.manager.DeleteContext(ctx.ID); err != nil { |
| 333 | return fmt.Errorf("%s", i18n.T("context.delete.error.failed", err)) |
| 334 | } |
| 335 | |
| 336 | fmt.Println(colorize(i18n.T("context.delete.success", ctx.Name), ColorGreen)) |
| 337 | |
| 338 | return nil |
| 339 | } |
| 340 | |
| 341 | // handleMerge merges multiple contexts into a new one. |
| 342 | func (h *ContextHandler) handleMerge(args []string) error { |
no test coverage detected