HandleValidationError handles configuration validation errors by guiding users through onboarding.
(cfg *config.Config, configPath string, noCacheFlag bool, activeProfile string)
| 18 | |
| 19 | // HandleValidationError handles configuration validation errors by guiding users through onboarding. |
| 20 | func HandleValidationError(cfg *config.Config, configPath string, noCacheFlag bool, activeProfile string) error { |
| 21 | fmt.Println(display.IconText("🔧", "Configuration Setup Required", cfg.ShowIcons)) |
| 22 | fmt.Println() |
| 23 | target, err := resolveOnboardingTarget(configPath) |
| 24 | if err != nil { |
| 25 | return fmt.Errorf("resolve onboarding target: %w", err) |
| 26 | } |
| 27 | |
| 28 | if target.exists { |
| 29 | fmt.Println("It looks like your configuration needs attention.") |
| 30 | } else { |
| 31 | fmt.Println("It looks like this is your first time running pvetui.") |
| 32 | } |
| 33 | validationErr := cfg.Validate() |
| 34 | if validationErr != nil { |
| 35 | fmt.Printf("Issue: %v\n", validationErr) |
| 36 | } |
| 37 | fmt.Println() |
| 38 | |
| 39 | if target.exists { |
| 40 | fmt.Println(display.IconText("✅", fmt.Sprintf("Found existing configuration at '%s'.", target.path), cfg.ShowIcons)) |
| 41 | if isKeyBindingValidationError(validationErr) { |
| 42 | fmt.Println(display.IconText("💡", fmt.Sprintf("Key binding errors must be fixed directly in '%s' under key_bindings.", target.path), cfg.ShowIcons)) |
| 43 | fmt.Println(display.IconText("💡", fmt.Sprintf("Please update the configuration file to resolve: %v", validationErr), cfg.ShowIcons)) |
| 44 | fmt.Println(display.IconText("🚪", "Exiting.", cfg.ShowIcons)) |
| 45 | os.Exit(0) |
| 46 | } |
| 47 | if !promptYesNo("Would you like to open the interactive editor to fix it?") { |
| 48 | fmt.Println(display.IconText("💡", fmt.Sprintf("Please update the configuration file to resolve: %v", validationErr), cfg.ShowIcons)) |
| 49 | fmt.Println(display.IconText("🚪", "Exiting.", cfg.ShowIcons)) |
| 50 | os.Exit(0) |
| 51 | } |
| 52 | |
| 53 | fmt.Println() |
| 54 | |
| 55 | targetProfile := activeProfile |
| 56 | if conflicts := cfg.FindGroupProfileNameConflicts(); len(conflicts) > 0 { |
| 57 | targetProfile = conflicts[0] |
| 58 | fmt.Println(display.IconText("💡", fmt.Sprintf("Opening the editor for profile '%s' so you can rename it (group name conflict).", targetProfile), cfg.ShowIcons)) |
| 59 | } |
| 60 | |
| 61 | res := launchConfigWizard(cfg, target.path, targetProfile) |
| 62 | if res.SopsEncrypted { |
| 63 | fmt.Println(display.IconText("✅", fmt.Sprintf("Configuration saved and encrypted with SOPS: %s", target.path), cfg.ShowIcons)) |
| 64 | } else if res.Saved { |
| 65 | fmt.Println(display.IconText("✅", "Configuration saved.", cfg.ShowIcons)) |
| 66 | } else if res.Canceled { |
| 67 | fmt.Println(display.IconText("ℹ️", "No changes were saved.", cfg.ShowIcons)) |
| 68 | } |
| 69 | |
| 70 | fmt.Println() |
| 71 | fmt.Println(display.IconText("✅", "Configuration is ready!", cfg.ShowIcons)) |
| 72 | fmt.Println(display.IconText("🔄", "Please re-run 'pvetui' to start the application with your updated configuration.", cfg.ShowIcons)) |
| 73 | fmt.Println(display.IconText("🚪", "Exiting.", cfg.ShowIcons)) |
| 74 | os.Exit(0) |
| 75 | } |
| 76 | |
| 77 | defaultPath := target.path |
no test coverage detected