Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions openapi_generator_cli/__init__.py
Comment thread
mxr marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ def run(args: list[str] | None = None) -> subprocess.CompletedProcess[bytes]:
return subprocess.run(arguments, check=False) # noqa: S603


def cli() -> None:
def cli(argv: list[str] | None = None) -> None:
"""Run the OpenAPI Generator CLI with the arguments provided on the command line."""
Comment thread
eggplants marked this conversation as resolved.
Outdated
argv = argv or sys.argv
args = []
if len(sys.argv) > 1:
args = sys.argv[1:]
run(args)
if len(argv) > 1:
args = argv[1:]
Comment thread
eggplants marked this conversation as resolved.
Outdated
sys.exit(run(args).returncode)


if __name__ == "__main__":
cli()
cli(sys.argv)
19 changes: 15 additions & 4 deletions tests/test_cli.py
Comment thread
eggplants marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

Comment thread
mxr marked this conversation as resolved.
import os
import re
from typing import TYPE_CHECKING

from openapi_generator_cli import run
import pytest

if TYPE_CHECKING:
import pytest
from openapi_generator_cli import cli, run


def test_cli_version(capfd: pytest.CaptureFixture[str]) -> None:
Expand Down Expand Up @@ -45,3 +43,16 @@ def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
"Found unexpected parameters: [--invalid-arg-404]"
in captured.err.split(os.linesep)[0]
)


def test_cli_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
with pytest.raises(SystemExit) as exc_info:
cli(["openapi-generator-cli", "--invalid-arg-404"])
assert exc_info.value.code == 1

captured = capfd.readouterr()
assert not captured.out
assert (
"Found unexpected parameters: [--invalid-arg-404]"
in captured.err.split(os.linesep)[0]
)