cmdGlobalEdit interactively edits global configuration
(ctx *ShellContext)
| 708 | |
| 709 | // cmdGlobalEdit interactively edits global configuration |
| 710 | func cmdGlobalEdit(ctx *ShellContext) error { |
| 711 | cfg, found, err := sshconfig.LoadGlobalConfig() |
| 712 | if err != nil { |
| 713 | return fmt.Errorf("failed to load global config: %w", err) |
| 714 | } |
| 715 | |
| 716 | if !found { |
| 717 | // Prompt user to create |
| 718 | fmt.Println("\nHost * block does not exist.") |
| 719 | line, err := ctx.liner.Prompt("Create it now? [Y/n]: ") |
| 720 | if err != nil { |
| 721 | return err |
| 722 | } |
| 723 | if strings.ToLower(strings.TrimSpace(line)) == "n" { |
| 724 | fmt.Println("Cancelled") |
| 725 | return nil |
| 726 | } |
| 727 | cfg = sshconfig.NewGlobalConfig() |
| 728 | } |
| 729 | |
| 730 | fmt.Println("\n=== Edit Global Configuration (Host *) ===") |
| 731 | fmt.Println("Press Enter to keep current value, type new value to change, or '-' to clear") |
| 732 | fmt.Println("Type '?' to see detailed help for an option") |
| 733 | fmt.Println() |
| 734 | |
| 735 | // Helper function to edit a single field |
| 736 | editField := func(key, current string) string { |
| 737 | desc, help, validValues := sshconfig.GetGlobalOptionHelp(key) |
| 738 | if current == "" { |
| 739 | current = "(not set)" |
| 740 | } |
| 741 | fmt.Printf("\n%s\n", desc) |
| 742 | if len(validValues) > 0 { |
| 743 | fmt.Printf("Valid values: %s\n", strings.Join(validValues, ", ")) |
| 744 | } |
| 745 | line, _ := ctx.liner.Prompt(fmt.Sprintf("%s [%s]: ", key, current)) |
| 746 | line = strings.TrimSpace(line) |
| 747 | if line == "?" { |
| 748 | fmt.Printf("\n%s\n\n", help) |
| 749 | line, _ = ctx.liner.Prompt(fmt.Sprintf("%s [%s]: ", key, current)) |
| 750 | line = strings.TrimSpace(line) |
| 751 | } |
| 752 | if line == "-" { |
| 753 | return "" |
| 754 | } |
| 755 | if line != "" { |
| 756 | return line |
| 757 | } |
| 758 | if current == "(not set)" { |
| 759 | return "" |
| 760 | } |
| 761 | // Return original value (unchanged) |
| 762 | return current |
| 763 | } |
| 764 | |
| 765 | // Edit ServerAliveInterval |
| 766 | result := editField("ServerAliveInterval", cfg.ServerAliveInterval) |
| 767 | if result != cfg.ServerAliveInterval { |
no test coverage detected