Skip to content

Commit 2bcf251

Browse files
committed
Ensure --num-variations is from 1 to 4
1 parent bd04ff7 commit 2bcf251

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

firefly/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def generate(
123123
raise typer.BadParameter("client_id must be provided as an option or via the FIREFLY_CLIENT_ID environment variable.")
124124
if not client_secret:
125125
raise typer.BadParameter("client_secret must be provided as an option or via the FIREFLY_CLIENT_SECRET environment variable.")
126+
if num_variations is not None and not (1 <= num_variations <= 4):
127+
typer.secho("--num-variations must be between 1 and 4", fg=typer.colors.RED, err=True)
128+
raise typer.Exit(code=-1)
126129
# Parse JSON for style/structure if provided
127130
style_obj = None
128131
if style:

tests/test_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,33 @@ def test_generate_invalid_json_structure(monkeypatch):
219219
)
220220
assert result.exit_code == 2
221221
assert "Invalid JSON for --structure" in result.output
222+
223+
def test_generate_invalid_num_variations(monkeypatch):
224+
# Test too low
225+
result = runner.invoke(
226+
app,
227+
[
228+
"image", "generate",
229+
"--client-id", "dummy_id",
230+
"--client-secret", "dummy_secret",
231+
"--prompt", "test",
232+
"--num-variations", "0",
233+
"--use-mocks"
234+
]
235+
)
236+
assert result.exit_code == -1
237+
assert "--num-variations must be between 1 and 4" in result.output
238+
# Test too high
239+
result = runner.invoke(
240+
app,
241+
[
242+
"image", "generate",
243+
"--client-id", "dummy_id",
244+
"--client-secret", "dummy_secret",
245+
"--prompt", "test",
246+
"--num-variations", "5",
247+
"--use-mocks"
248+
]
249+
)
250+
assert result.exit_code == -1
251+
assert "--num-variations must be between 1 and 4" in result.output

0 commit comments

Comments
 (0)