summaryrefslogtreecommitdiff
path: root/internal/cli/apikeys.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-08 10:11:53 +0300
committerPaul Buetow <paul@buetow.org>2026-04-08 10:11:53 +0300
commitd04a2b91fac52d5ff170b96f4f11846ddf7e01b8 (patch)
tree70c7a1eee0a3f51ffc3c93ea375c9efa41d91abf /internal/cli/apikeys.go
parentfe773e70eff53efe32270862f5be0d900e50eea3 (diff)
refactor(cli): split command.go into flags, config, apikeys (SRP)
Move cobra flag registration, viper binding, and explicit-flag tracking into flags.go alongside Flags and NewFlags. Add config.go for InitConfig and apikeys.go for GetOpenAIKey/GetGoogleAPIKey. command.go now only defines CreateRootCommand. Made-with: Cursor
Diffstat (limited to 'internal/cli/apikeys.go')
-rw-r--r--internal/cli/apikeys.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/cli/apikeys.go b/internal/cli/apikeys.go
new file mode 100644
index 0000000..0bcaa49
--- /dev/null
+++ b/internal/cli/apikeys.go
@@ -0,0 +1,35 @@
+package cli
+
+import (
+ "os"
+
+ "github.com/spf13/viper"
+)
+
+// GetOpenAIKey retrieves the OpenAI API key from environment or config
+func GetOpenAIKey() string {
+ // First check environment variable
+ if key := os.Getenv("OPENAI_API_KEY"); key != "" {
+ return key
+ }
+
+ // Then check config file
+ return viper.GetString("audio.openai_key")
+}
+
+// GetGoogleAPIKey retrieves the Google API key from GOOGLE_API_KEY or config.
+// It prefers image.google_api_key and falls back to google.api_key for older configs.
+func GetGoogleAPIKey() string {
+ // First check environment variable
+ if key := os.Getenv("GOOGLE_API_KEY"); key != "" {
+ return key
+ }
+
+ // Then check config file
+ if key := viper.GetString("image.google_api_key"); key != "" {
+ return key
+ }
+
+ // Fall back to the legacy key for compatibility with older configs.
+ return viper.GetString("google.api_key")
+}