cmdDelete deletes an SSH host configuration
(ctx *ShellContext, args string)
| 378 | |
| 379 | // cmdDelete deletes an SSH host configuration |
| 380 | func cmdDelete(ctx *ShellContext, args string) error { |
| 381 | hostName := strings.TrimSpace(args) |
| 382 | if hostName == "" { |
| 383 | fmt.Println("Usage: delete <host>") |
| 384 | return nil |
| 385 | } |
| 386 | |
| 387 | // Check if host exists |
| 388 | cfg, err := sshconfig.LoadHostConfig(hostName) |
| 389 | if err != nil { |
| 390 | return fmt.Errorf("host not found: %w", err) |
| 391 | } |
| 392 | |
| 393 | // Show details and confirm |
| 394 | fmt.Printf("\n=== Delete Host: %s ===\n", cfg.Name) |
| 395 | fmt.Printf("Hostname: %s\n", cfg.Hostname) |
| 396 | if cfg.User != "" { |
| 397 | fmt.Printf("User: %s\n", cfg.User) |
| 398 | } |
| 399 | |
| 400 | line, _ := ctx.liner.Prompt("\nType 'yes' to confirm deletion: ") |
| 401 | line = cleanLinerInput(line) |
| 402 | if line != "yes" { |
| 403 | fmt.Println("Cancelled") |
| 404 | return nil |
| 405 | } |
| 406 | |
| 407 | if err := sshconfig.DeleteHostConfig(hostName); err != nil { |
| 408 | return fmt.Errorf("failed to delete: %w", err) |
| 409 | } |
| 410 | |
| 411 | if err := reloadHosts(ctx); err != nil { |
| 412 | fmt.Printf("Warning: Failed to reload hosts: %v\n", err) |
| 413 | } |
| 414 | |
| 415 | fmt.Printf("\n✓ Host '%s' deleted from ~/.ssh/config\n", hostName) |
| 416 | return nil |
| 417 | } |
| 418 | |
| 419 | // cmdShow displays detailed host configuration |
| 420 | func cmdShow(ctx *ShellContext, args string) error { |
no test coverage detected