summaryrefslogtreecommitdiff
path: root/internal/cli
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-01 15:41:42 +0300
committerPaul Buetow <paul@buetow.org>2026-04-01 15:41:42 +0300
commit8e7063e78f5067f79d2a1a9e2b0fc2fde86d1f6e (patch)
treeeef470c2663671e1a8fce8273677fb844055e1df /internal/cli
parent3967d8dca4ebe87e43d243c5bbffe34ca0dcab51 (diff)
z7: keep Nano Banana CLI additive
Diffstat (limited to 'internal/cli')
-rw-r--r--internal/cli/command.go2
-rw-r--r--internal/cli/command_test.go41
-rw-r--r--internal/cli/flags.go2
-rw-r--r--internal/cli/flags_test.go2
4 files changed, 42 insertions, 5 deletions
diff --git a/internal/cli/command.go b/internal/cli/command.go
index 7bf57d6..ad32d23 100644
--- a/internal/cli/command.go
+++ b/internal/cli/command.go
@@ -55,7 +55,7 @@ func setupFlags(cmd *cobra.Command, flags *Flags) {
// Local flags
cmd.Flags().StringVarP(&flags.OutputDir, "output", "o", defaultOutputDir, "Output directory")
cmd.Flags().StringVarP(&flags.AudioFormat, "format", "f", flags.AudioFormat, "Audio format (wav or mp3)")
- cmd.Flags().StringVar(&flags.ImageAPI, "image-api", flags.ImageAPI, "Image source (openai or nanobanana; default: nanobanana)")
+ cmd.Flags().StringVar(&flags.ImageAPI, "image-api", flags.ImageAPI, "Image source (openai or nanobanana; default: openai)")
cmd.Flags().StringVar(&flags.BatchFile, "batch", "", "Process words from file (one per line)")
cmd.Flags().BoolVar(&flags.SkipAudio, "skip-audio", false, "Skip audio generation")
cmd.Flags().BoolVar(&flags.SkipImages, "skip-images", false, "Skip image download")
diff --git a/internal/cli/command_test.go b/internal/cli/command_test.go
index ab21c49..1ebff95 100644
--- a/internal/cli/command_test.go
+++ b/internal/cli/command_test.go
@@ -100,8 +100,8 @@ func TestSetupFlags(t *testing.T) {
if imageAPIFlag == nil {
t.Fatal("image-api flag not found")
}
- if imageAPIFlag.DefValue != "nanobanana" {
- t.Errorf("Expected default image-api to be nanobanana, got %s", imageAPIFlag.DefValue)
+ if imageAPIFlag.DefValue != "openai" {
+ t.Errorf("Expected default image-api to be openai, got %s", imageAPIFlag.DefValue)
}
nanoBananaModelFlag := cmd.Flags().Lookup("nanobanana-model")
@@ -275,24 +275,35 @@ func TestGetGoogleAPIKey(t *testing.T) {
name string
envKey string
configKey string
+ legacyKey string
expected string
}{
{
name: "from environment",
envKey: "env-google-key",
configKey: "config-google-key",
+ legacyKey: "legacy-google-key",
expected: "env-google-key",
},
{
name: "from config when no env",
envKey: "",
configKey: "config-google-key",
+ legacyKey: "legacy-google-key",
expected: "config-google-key",
},
{
+ name: "falls back to legacy config key",
+ envKey: "",
+ configKey: "",
+ legacyKey: "legacy-google-key",
+ expected: "legacy-google-key",
+ },
+ {
name: "empty when neither set",
envKey: "",
configKey: "",
+ legacyKey: "",
expected: "",
},
}
@@ -319,6 +330,9 @@ func TestGetGoogleAPIKey(t *testing.T) {
if tt.configKey != "" {
viper.Set("image.google_api_key", tt.configKey)
}
+ if tt.legacyKey != "" {
+ viper.Set("google.api_key", tt.legacyKey)
+ }
got := GetGoogleAPIKey()
if got != tt.expected {
@@ -328,6 +342,26 @@ func TestGetGoogleAPIKey(t *testing.T) {
}
}
+func TestGetGoogleAPIKey_PrefersImageConfigOverLegacyConfig(t *testing.T) {
+ originalConfig := viper.New()
+ *originalConfig = *viper.GetViper()
+ defer func() {
+ *viper.GetViper() = *originalConfig
+ }()
+
+ viper.Reset()
+ if err := os.Unsetenv("GOOGLE_API_KEY"); err != nil {
+ t.Fatalf("Failed to unset GOOGLE_API_KEY: %v", err)
+ }
+
+ viper.Set("image.google_api_key", "new-google-key")
+ viper.Set("google.api_key", "legacy-google-key")
+
+ if got := GetGoogleAPIKey(); got != "new-google-key" {
+ t.Fatalf("GetGoogleAPIKey() = %v, want %v", got, "new-google-key")
+ }
+}
+
func TestBindFlagsToViper(t *testing.T) {
// Save original viper state
originalConfig := viper.New()
@@ -382,4 +416,7 @@ func TestBindFlagsToViper(t *testing.T) {
if viper.GetString("image.nanobanana_text_model") != "gemini-2.5-flash" {
t.Errorf("Expected image.nanobanana_text_model to be gemini-2.5-flash, got %s", viper.GetString("image.nanobanana_text_model"))
}
+ if viper.GetString("image.provider") != "openai" {
+ t.Errorf("Expected image.provider to be openai by default, got %s", viper.GetString("image.provider"))
+ }
}
diff --git a/internal/cli/flags.go b/internal/cli/flags.go
index 172b854..9c00051 100644
--- a/internal/cli/flags.go
+++ b/internal/cli/flags.go
@@ -45,7 +45,7 @@ type Flags struct {
func NewFlags() *Flags {
return &Flags{
AudioFormat: "mp3",
- ImageAPI: "nanobanana",
+ ImageAPI: "openai",
DeckName: "Bulgarian Vocabulary",
OpenAIModel: "gpt-4o-mini-tts",
OpenAISpeed: 0.9,
diff --git a/internal/cli/flags_test.go b/internal/cli/flags_test.go
index d5c2ccb..d40d8a2 100644
--- a/internal/cli/flags_test.go
+++ b/internal/cli/flags_test.go
@@ -15,7 +15,7 @@ func TestNewFlags(t *testing.T) {
expected interface{}
}{
{"AudioFormat", flags.AudioFormat, "mp3"},
- {"ImageAPI", flags.ImageAPI, "nanobanana"},
+ {"ImageAPI", flags.ImageAPI, "openai"},
{"DeckName", flags.DeckName, "Bulgarian Vocabulary"},
{"OpenAIModel", flags.OpenAIModel, "gpt-4o-mini-tts"},
{"OpenAISpeed", flags.OpenAISpeed, 0.9},