feat(config): add typed module-input fields with defaults

This commit is contained in:
MDietermann
2026-04-14 08:40:29 +02:00
parent fcc24b99b2
commit ffd18c5382
3 changed files with 166 additions and 4 deletions

View File

@@ -14,12 +14,50 @@ import (
//go:embed defaults.yaml
var defaultsYAML []byte
type Packages struct {
Base []string `yaml:"base"`
}
type ArduinoCLIConfig struct {
Version string `yaml:"version"`
URL string `yaml:"url"`
Cores []string `yaml:"cores"`
}
type ZshPlugin struct {
Name string `yaml:"name"`
Repo string `yaml:"repo"`
}
type ZshConfig struct {
OhMyZshRepo string `yaml:"oh_my_zsh_repo"`
Plugins []ZshPlugin `yaml:"plugins"`
}
type ZellijConfig struct {
ConfigURL string `yaml:"config_url"`
}
type ThemesConfig struct {
Source string `yaml:"source"`
}
type ShellConfigBlock struct {
Name string `yaml:"name"`
File string `yaml:"file"`
Content string `yaml:"content"`
}
type ShellConfigSection struct {
Blocks []ShellConfigBlock `yaml:"blocks"`
}
// Config is the fully-resolved runtime configuration.
type Config struct {
Version int `yaml:"version"`
ExtraPackages []string `yaml:"extra_packages"`
DisabledModules []string `yaml:"disabled_modules"`
ThemeOverrides map[string]string `yaml:"theme_overrides"`
Version int `yaml:"version"`
ExtraPackages []string `yaml:"extra_packages"`
DisabledModules []string `yaml:"disabled_modules"`
ThemeOverrides map[string]string `yaml:"theme_overrides"`
Packages Packages `yaml:"packages"`
Fonts []string `yaml:"fonts"`
ArduinoCLI ArduinoCLIConfig `yaml:"arduino_cli"`
Zsh ZshConfig `yaml:"zsh"`
Zellij ZellijConfig `yaml:"zellij"`
Themes ThemesConfig `yaml:"themes"`
ShellConfig ShellConfigSection `yaml:"shell_config"`
}
const currentVersion = 1
@@ -78,5 +116,26 @@ func merge(base, over Config) Config {
}
out.ThemeOverrides = merged
}
if len(over.Packages.Base) > 0 {
out.Packages = over.Packages
}
if len(over.Fonts) > 0 {
out.Fonts = over.Fonts
}
if over.ArduinoCLI.Version != "" {
out.ArduinoCLI = over.ArduinoCLI
}
if over.Zsh.OhMyZshRepo != "" {
out.Zsh = over.Zsh
}
if over.Zellij.ConfigURL != "" {
out.Zellij = over.Zellij
}
if over.Themes.Source != "" {
out.Themes = over.Themes
}
if len(over.ShellConfig.Blocks) > 0 {
out.ShellConfig = over.ShellConfig
}
return out
}