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 //go:embed defaults.yaml
var defaultsYAML []byte 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. // Config is the fully-resolved runtime configuration.
type Config struct { type Config struct {
Version int `yaml:"version"` Version int `yaml:"version"`
ExtraPackages []string `yaml:"extra_packages"` ExtraPackages []string `yaml:"extra_packages"`
DisabledModules []string `yaml:"disabled_modules"` DisabledModules []string `yaml:"disabled_modules"`
ThemeOverrides map[string]string `yaml:"theme_overrides"` 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 const currentVersion = 1
@@ -78,5 +116,26 @@ func merge(base, over Config) Config {
} }
out.ThemeOverrides = merged 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 return out
} }

View File

@@ -48,6 +48,31 @@ theme_overrides:
} }
} }
func TestDefaultsCarryModuleInputs(t *testing.T) {
cfg, err := Load("/nonexistent/overlay.yaml")
if err != nil {
t.Fatal(err)
}
if len(cfg.Packages.Base) == 0 {
t.Error("Packages.Base empty")
}
if len(cfg.Fonts) == 0 {
t.Error("Fonts empty")
}
if cfg.ArduinoCLI.Version == "" {
t.Error("ArduinoCLI.Version empty")
}
if cfg.ArduinoCLI.URL == "" {
t.Error("ArduinoCLI.URL empty")
}
if cfg.Zsh.OhMyZshRepo == "" {
t.Error("Zsh.OhMyZshRepo empty")
}
if len(cfg.ShellConfig.Blocks) == 0 {
t.Error("ShellConfig.Blocks empty")
}
}
func TestLoadRejectsUnknownVersion(t *testing.T) { func TestLoadRejectsUnknownVersion(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
path := filepath.Join(dir, "overlay.yaml") path := filepath.Join(dir, "overlay.yaml")

View File

@@ -2,3 +2,81 @@ version: 1
extra_packages: [] extra_packages: []
disabled_modules: [] disabled_modules: []
theme_overrides: {} theme_overrides: {}
packages:
base:
- base-devel
- git
- curl
- wget
- unzip
- zip
- tree
- htop
- neofetch
- ripgrep
- fd
- bat
- eza
- jq
- zsh
- clang
- ca-certificates
fonts:
- ttf-jetbrains-mono-nerd
arduino_cli:
version: "0.35.3"
url: "https://github.com/arduino/arduino-cli/releases/download/v0.35.3/arduino-cli_0.35.3_Linux_64bit.tar.gz"
cores:
- arduino:avr
zsh:
oh_my_zsh_repo: "https://github.com/ohmyzsh/ohmyzsh.git"
plugins:
- name: zsh-autosuggestions
repo: https://github.com/zsh-users/zsh-autosuggestions
- name: zsh-syntax-highlighting
repo: https://github.com/zsh-users/zsh-syntax-highlighting.git
zellij:
config_url: ""
themes:
source: "lib/themes"
shell_config:
blocks:
- name: archduino-path
file: ".zshrc"
content: |
export PATH="$HOME/.local/bin:$PATH"
- name: archduino-editor
file: ".zshrc"
content: |
export EDITOR="nvim"
export VISUAL="nvim"
- name: archduino-starship
file: ".zshrc"
content: |
eval "$(starship init zsh)"
- name: archduino-zellij
file: ".zshrc"
content: |
if [[ -z "$ZELLIJ" ]]; then
zellij attach --create archduino
fi
- name: archduino-aliases
file: ".zshrc"
content: |
alias adev="zellij --layout arduino"
alias ac="arduino-cli"
alias acc="arduino-cli compile"
alias acu="arduino-cli upload"
alias acm="arduino-cli monitor"
alias acb="arduino-cli board list"
alias lg="lazygit"
alias v="nvim"
alias y="yazi"
alias theme="archduino-theme"