Bootstrap handles the complete application bootstrap process.
(opts BootstrapOptions)
| 148 | |
| 149 | // Bootstrap handles the complete application bootstrap process. |
| 150 | func Bootstrap(opts BootstrapOptions) (*BootstrapResult, error) { |
| 151 | // Handle version flag |
| 152 | if opts.Version { |
| 153 | printVersion() |
| 154 | return nil, nil |
| 155 | } |
| 156 | |
| 157 | // Initialize configuration |
| 158 | cfg := config.NewConfig() |
| 159 | |
| 160 | // Resolve configuration path |
| 161 | configPath := ResolveConfigPath(opts.ConfigPath) |
| 162 | if opts.FlagAgeDir != "" { |
| 163 | expandedAgeDir := config.ExpandHomePath(opts.FlagAgeDir) |
| 164 | cfg.AgeDir = expandedAgeDir |
| 165 | config.SetAgeDirOverride(expandedAgeDir) |
| 166 | } |
| 167 | |
| 168 | // Handle profile listing BEFORE wizard/startup flow. |
| 169 | if opts.ListProfiles { |
| 170 | if configPath != "" { |
| 171 | if err := cfg.MergeWithFile(configPath); err != nil { |
| 172 | return nil, fmt.Errorf("failed to load config file: %w", err) |
| 173 | } |
| 174 | } |
| 175 | cfg.SetDefaults() |
| 176 | selectedProfile, err := profile.ResolveProfile(opts.Profile, cfg) |
| 177 | if err != nil { |
| 178 | return nil, fmt.Errorf("profile resolution failed: %w", err) |
| 179 | } |
| 180 | fmt.Print(formatProfileAndGroupList(cfg, selectedProfile)) |
| 181 | return nil, nil |
| 182 | } |
| 183 | |
| 184 | // Handle config wizard BEFORE config loading and profile resolution |
| 185 | // This allows the wizard to work even when no config file exists |
| 186 | if opts.ConfigWizard { |
| 187 | configPath = ResolveConfigPathForWizard(opts.ConfigPath) |
| 188 | // Seed from template if the config doesn't exist so the wizard matches onboarding defaults. |
| 189 | if configPath != "" { |
| 190 | if _, err := os.Stat(configPath); err != nil { |
| 191 | if os.IsNotExist(err) { |
| 192 | if _, err := config.CreateDefaultConfigFileAt(configPath); err != nil { |
| 193 | return nil, fmt.Errorf("create default config: %w", err) |
| 194 | } |
| 195 | } else { |
| 196 | return nil, fmt.Errorf("check config path: %w", err) |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | _ = cfg.MergeWithFile(configPath) // Ignore errors for config wizard |
| 201 | } |
| 202 | |
| 203 | // Set defaults for config wizard |
| 204 | cfg.SetDefaults() |
| 205 | |
| 206 | // Handle profile selection for config wizard |
| 207 | selectedProfile, err := profile.ResolveProfile(opts.Profile, cfg) |