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
2 changes: 2 additions & 0 deletions .github/workflows/test-redistribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
run: |
cd dist/fastapi_cli*/
pip install -r requirements-tests.txt
env:
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
- name: Run source distribution tests
run: |
cd dist/fastapi_cli*/
Expand Down
3 changes: 3 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pytest >=4.4.0,<8.0.0
coverage[toml] >=6.2,<8.0
mypy ==1.4.1
ruff ==0.2.0
# Needed explicitly by fastapi-cli-slim
fastapi-slim
uvicorn
9 changes: 9 additions & 0 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _run(
host: str = "127.0.0.1",
port: int = 8000,
reload: bool = True,
workers: Union[int, None] = None,
root_path: str = "",
command: str,
app: Union[str, None] = None,
Expand Down Expand Up @@ -85,6 +86,7 @@ def _run(
host=host,
port=port,
reload=reload,
workers=workers,
root_path=root_path,
proxy_headers=proxy_headers,
)
Expand Down Expand Up @@ -200,6 +202,12 @@ def run(
help="Enable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development."
),
] = False,
workers: Annotated[
Union[int, None],
typer.Option(
help="Use multiple worker processes. Mutually exclusive with the --reload flag."
),
] = None,
root_path: Annotated[
str,
typer.Option(
Expand Down Expand Up @@ -249,6 +257,7 @@ def run(
host=host,
port=port,
reload=reload,
workers=workers,
root_path=root_path,
app=app,
command="run",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_dev() -> None:
"host": "127.0.0.1",
"port": 8000,
"reload": True,
"workers": None,
"root_path": "",
"proxy_headers": True,
}
Expand Down Expand Up @@ -67,6 +68,7 @@ def test_dev_args() -> None:
"host": "192.168.0.2",
"port": 8080,
"reload": False,
"workers": None,
"root_path": "/api",
"proxy_headers": False,
}
Expand All @@ -92,6 +94,7 @@ def test_run() -> None:
"host": "0.0.0.0",
"port": 8000,
"reload": False,
"workers": None,
"root_path": "",
"proxy_headers": True,
}
Expand All @@ -118,6 +121,8 @@ def test_run_args() -> None:
"--port",
"8080",
"--no-reload",
"--workers",
"2",
"--root-path",
"/api",
"--app",
Expand All @@ -133,6 +138,7 @@ def test_run_args() -> None:
"host": "192.168.0.2",
"port": 8080,
"reload": False,
"workers": 2,
"root_path": "/api",
"proxy_headers": False,
}
Expand Down Expand Up @@ -171,6 +177,7 @@ def test_dev_help() -> None:
assert "Enable auto-reload of the server when (code) files change." in result.output
assert "The root path is used to tell your app" in result.output
assert "The name of the variable that contains the FastAPI app" in result.output
assert "Use multiple worker processes." not in result.output


def test_run_help() -> None:
Expand All @@ -191,6 +198,7 @@ def test_run_help() -> None:
assert "Enable auto-reload of the server when (code) files change." in result.output
assert "The root path is used to tell your app" in result.output
assert "The name of the variable that contains the FastAPI app" in result.output
assert "Use multiple worker processes." in result.output


def test_callback_help() -> None:
Expand Down