MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / createEmbeddedConfigWizard

Method createEmbeddedConfigWizard

internal/ui/components/profile_wizard.go:17–585  ·  view source on GitHub ↗

createEmbeddedConfigWizard creates a config wizard that doesn't call app.Stop() when canceling

(cfg *config.Config, resultChan chan<- WizardResult)

Source from the content-addressed store, hash-verified

15
16// createEmbeddedConfigWizard creates a config wizard that doesn't call app.Stop() when canceling
17func (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

Callers 2

showAddProfileDialogMethod · 0.95
showEditProfileDialogMethod · 0.95

Calls 15

FindDefaultConfigPathFunction · 0.92
GetDefaultConfigPathFunction · 0.92
DecryptFieldFunction · 0.92
ExpandHomePathFunction · 0.92
newStandardFormFunction · 0.85
isSOPSEncryptedFunction · 0.85
findSOPSRuleFunction · 0.85
showWizardModalFunction · 0.85
SaveConfigToFileFunction · 0.85
CreateConfirmDialogFunction · 0.85
SetFieldWidthMethod · 0.80
SetLabelMethod · 0.80

Tested by

no test coverage detected