MCPcopy Create free account
hub / github.com/Mister-leo/fssh / cmdDelete

Function cmdDelete

cmd/fssh/shell_commands.go:380–417  ·  view source on GitHub ↗

cmdDelete deletes an SSH host configuration

(ctx *ShellContext, args string)

Source from the content-addressed store, hash-verified

378
379// cmdDelete deletes an SSH host configuration
380func 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
420func cmdShow(ctx *ShellContext, args string) error {

Callers 1

runShellFunction · 0.85

Calls 4

LoadHostConfigFunction · 0.92
DeleteHostConfigFunction · 0.92
cleanLinerInputFunction · 0.85
reloadHostsFunction · 0.85

Tested by

no test coverage detected