summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-22 09:07:47 +0300
committerPaul Buetow <paul@buetow.org>2026-04-22 09:07:47 +0300
commit519be7e7dd12cbe3c85f90cf06d65b377eb22a3c (patch)
tree59bc012999bd03a26e5fa6c097741ede7b211296 /internal/config
parent24dd98eaa9759884b17f18c729d498af6ec70e9e (diff)
add logo
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go10
-rw-r--r--internal/config/config_test.go27
2 files changed, 37 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index f778637..754c816 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -197,6 +197,7 @@ func Load(configPath string) (*Config, error) {
return nil, fmt.Errorf("decode config: %w", err)
}
+ applyEnvFallbacks(cfg)
cfg.normalize()
if err := cfg.validate(); err != nil {
return nil, err
@@ -393,3 +394,12 @@ func setDefaults(v *viper.Viper, cfg *Config) {
v.SetDefault("prompts_dir", cfg.PromptsDir)
}
+
+func applyEnvFallbacks(cfg *Config) {
+ if cfg == nil {
+ return
+ }
+ if cfg.API.GoogleAPIKey == "" {
+ cfg.API.GoogleAPIKey = os.Getenv("GOOGLE_API_KEY")
+ }
+}
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index f825f58..1a53486 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -101,6 +101,33 @@ narration:
}
}
+func TestLoadFallsBackToGoogleAPIKeyEnv(t *testing.T) {
+ t.Setenv("GOOGLE_API_KEY", "fallback-key")
+
+ cfg, err := Load("")
+ if err != nil {
+ t.Fatalf("Load() error = %v", err)
+ }
+
+ if got, want := cfg.GoogleAPIKey(), "fallback-key"; got != want {
+ t.Fatalf("GoogleAPIKey() = %q, want %q", got, want)
+ }
+}
+
+func TestLoadPrefersComicForgeGoogleAPIKeyEnv(t *testing.T) {
+ t.Setenv("GOOGLE_API_KEY", "fallback-key")
+ t.Setenv("COMICFORGE_API_GOOGLE_API_KEY", "comicforge-key")
+
+ cfg, err := Load("")
+ if err != nil {
+ t.Fatalf("Load() error = %v", err)
+ }
+
+ if got, want := cfg.GoogleAPIKey(), "comicforge-key"; got != want {
+ t.Fatalf("GoogleAPIKey() = %q, want %q", got, want)
+ }
+}
+
func TestRenderPrompt(t *testing.T) {
tmpDir := t.TempDir()
cfg := DefaultConfig()