Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 11 additions & 6 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,12 +56,17 @@ def run(args: list[str] | None = None) -> subprocess.CompletedProcess[bytes]:
return subprocess.run(arguments, check=False) # noqa: S603


def cli() -> None:
"""Run the OpenAPI Generator CLI with the arguments provided on the command line."""
args = []
if len(sys.argv) > 1:
args = sys.argv[1:]
run(args)
def cli(argv: list[str] | None = None) -> None:
"""Run the OpenAPI Generator CLI with the arguments provided on the command line.

Args:
argv (list[str], optional):
The command-line arguments to pass to the OpenAPI Generator CLI.
If not provided, sys.argv is used.

"""
args = (argv or sys.argv)[1:]
sys.exit(run(args).returncode)


if __name__ == "__main__":
Expand Down
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]
)
Loading