createEmbeddedConfigWizard creates a config wizard that doesn't call app.Stop() when canceling
(cfg *config.Config, resultChan chan<- WizardResult)
| 15 | |
| 16 | // createEmbeddedConfigWizard creates a config wizard that doesn't call app.Stop() when canceling |
| 17 | func (a *App) createEmbeddedConfigWizard(cfg *config.Config, resultChan chan<- WizardResult) tview.Primitive { |
| 18 | form := newStandardForm().SetHorizontal(false) |
| 19 | pages := tview.NewPages() |
| 20 | pages.AddPage("form", form, true, true) |
| 21 | |
| 22 | // Use the app's actual config path instead of hardcoding the default path |
| 23 | configPath := a.configPath |
| 24 | if configPath == "" { |
| 25 | // Fallback to default path if no path is stored |
| 26 | var found bool |
| 27 | configPath, found = config.FindDefaultConfigPath() |
| 28 | if !found { |
| 29 | configPath = config.GetDefaultConfigPath() |
| 30 | } |
| 31 | } |
| 32 | wasSOPS := false |
| 33 | if configPath != "" { |
| 34 | if data, err := os.ReadFile(configPath); err == nil { |
| 35 | wasSOPS = isSOPSEncrypted(configPath, data) |
| 36 | } |
| 37 | } |
| 38 | // Check for .sops.yaml in config dir or parents |
| 39 | sopsRuleExists := false |
| 40 | if configPath != "" { |
| 41 | sopsRuleExists = findSOPSRule(filepath.Dir(configPath)) |
| 42 | } |
| 43 | |
| 44 | // Determine if this is a new profile or editing existing |
| 45 | isNewProfile := cfg.DefaultProfile == "new_profile" |
| 46 | |
| 47 | // For new profiles, defer creating the temp entry until Save. Avoid polluting list on cancel. |
| 48 | |
| 49 | // Add profile name field at the top |
| 50 | var profileName string |
| 51 | |
| 52 | if isNewProfile { |
| 53 | form.AddInputField("Profile Name", "", 20, nil, func(text string) { |
| 54 | profileName = strings.TrimSpace(text) |
| 55 | }) |
| 56 | } else { |
| 57 | // For editing, allow renaming the profile |
| 58 | profileName = cfg.DefaultProfile // Start with current name |
| 59 | form.AddInputField("Profile Name", cfg.DefaultProfile, 20, nil, func(text string) { |
| 60 | profileName = strings.TrimSpace(text) |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | // Determine which data to use for form fields |
| 65 | var addr, user, password, tokenID, tokenSecret, realm, apiPath, sshUser, vmSSHUser, sshKeyfile, vmSSHKeyfile, groupString string |
| 66 | var sshJumpHostAddr, sshJumpHostUser, sshJumpHostKeyfile, sshJumpHostPort string |
| 67 | var insecure, useJumpHost bool |
| 68 | |
| 69 | // If we have profiles and a default profile, use profile data |
| 70 | //nolint:dupl // Shared with config wizard but kept inline for clarity |
| 71 | if len(cfg.Profiles) > 0 && cfg.DefaultProfile != "" { |
| 72 | if profile, exists := cfg.Profiles[cfg.DefaultProfile]; exists { |
| 73 | addr = profile.Addr |
| 74 | user = profile.User |
no test coverage detected