ResolveProfile determines which profile to use based on command line flags, environment variables, and configuration defaults.
(flagProfile string, cfg *config.Config)
| 14 | // ResolveProfile determines which profile to use based on command line flags, |
| 15 | // environment variables, and configuration defaults. |
| 16 | func ResolveProfile(flagProfile string, cfg *config.Config) (string, error) { |
| 17 | // Check command line flag first (highest priority) |
| 18 | if flagProfile != "" { |
| 19 | return flagProfile, nil |
| 20 | } |
| 21 | |
| 22 | // Check environment variable |
| 23 | if envProfile := os.Getenv("PVETUI_PROFILE"); envProfile != "" { |
| 24 | return envProfile, nil |
| 25 | } |
| 26 | |
| 27 | // Check configuration default (only if profiles exist) |
| 28 | if cfg.DefaultProfile != "" && len(cfg.Profiles) > 0 { |
| 29 | return cfg.DefaultProfile, nil |
| 30 | } |
| 31 | |
| 32 | // No default set - return empty string to signal interactive selection is needed |
| 33 | return "", nil |
| 34 | } |
| 35 | |
| 36 | // ValidateProfile ensures the selected profile exists and is valid. |
| 37 | func ValidateProfile(profileName string, cfg *config.Config) error { |