NewConfigWizardPage creates a new configuration wizard page.
(app *tview.Application, cfg *config.Config, configPath string, saveFn func(*config.Config) error, cancelFn func(), resultChan chan<- WizardResult, targetProfile string)
| 111 | |
| 112 | // NewConfigWizardPage creates a new configuration wizard page. |
| 113 | func NewConfigWizardPage(app *tview.Application, cfg *config.Config, configPath string, saveFn func(*config.Config) error, cancelFn func(), resultChan chan<- WizardResult, targetProfile string) tview.Primitive { |
| 114 | // Detect if original config was SOPS-encrypted |
| 115 | wasSOPS := false |
| 116 | |
| 117 | if configPath != "" { |
| 118 | if data, err := os.ReadFile(configPath); err == nil { |
| 119 | wasSOPS = isSOPSEncrypted(configPath, data) |
| 120 | } |
| 121 | } |
| 122 | // Check for .sops.yaml in config dir or parents |
| 123 | sopsRuleExists := false |
| 124 | if configPath != "" { |
| 125 | sopsRuleExists = findSOPSRule(filepath.Dir(configPath)) |
| 126 | } |
| 127 | |
| 128 | form := newStandardForm().SetHorizontal(false) |
| 129 | pages := tview.NewPages() |
| 130 | pages.AddPage("form", form, true, true) |
| 131 | |
| 132 | // Add profile name field at the top |
| 133 | var profileName string |
| 134 | originalProfileName := "" |
| 135 | |
| 136 | // Determine if we are editing an existing profile |
| 137 | var isEditing bool |
| 138 | resolveProfileForWizard := func(candidate string) (string, bool) { |
| 139 | if candidate == "" { |
| 140 | return "", false |
| 141 | } |
| 142 | |
| 143 | if cfg.Profiles != nil { |
| 144 | if _, exists := cfg.Profiles[candidate]; exists { |
| 145 | return candidate, true |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // If a group name is supplied, edit the first member profile (stable order). |
| 150 | if cfg.IsGroup(candidate) { |
| 151 | members := cfg.GetProfileNamesInGroup(candidate) |
| 152 | if len(members) > 0 { |
| 153 | if _, exists := cfg.Profiles[members[0]]; exists { |
| 154 | return members[0], true |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Unknown name: treat as creating a new profile. |
| 160 | return candidate, false |
| 161 | } |
| 162 | |
| 163 | if targetProfile != "" { |
| 164 | // User requested specific profile/group |
| 165 | profileName, isEditing = resolveProfileForWizard(targetProfile) |
| 166 | } else { |
| 167 | // Fallback to default behavior |
| 168 | // If we have profiles, default to editing the default profile |
| 169 | if len(cfg.Profiles) > 0 && cfg.DefaultProfile != "" { |
| 170 | profileName, isEditing = resolveProfileForWizard(cfg.DefaultProfile) |
no test coverage detected