From d04a2b91fac52d5ff170b96f4f11846ddf7e01b8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 8 Apr 2026 10:11:53 +0300 Subject: 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 --- internal/cli/apikeys.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/cli/apikeys.go (limited to 'internal/cli/apikeys.go') 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") +} -- cgit v1.2.3