Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def _run(
app: Union[str, None] = None,
entrypoint: Union[str, None] = None,
proxy_headers: bool = False,
reload_dirs: Union[str, None] = None,
forwarded_allow_ips: Union[str, None] = None,
) -> None:
with get_rich_toolkit() as toolkit:
Expand Down Expand Up @@ -185,6 +186,7 @@ def _run(
workers=workers,
root_path=root_path,
proxy_headers=proxy_headers,
reload_dirs=reload_dirs.split(",") if reload_dirs else None,
forwarded_allow_ips=forwarded_allow_ips,
log_config=get_uvicorn_log_config(),
)
Expand Down Expand Up @@ -244,6 +246,12 @@ def dev(
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info."
),
] = True,
reload_dirs: Annotated[
Union[str, None],
typer.Option(
help="Comma separated list of directories to watch for changes in. If not provided, by default the whole current directory will be watched."
),
] = None,
forwarded_allow_ips: Annotated[
Union[str, None],
typer.Option(
Expand Down Expand Up @@ -286,6 +294,7 @@ def dev(
entrypoint=entrypoint,
command="dev",
proxy_headers=proxy_headers,
reload_dirs=reload_dirs,
forwarded_allow_ips=forwarded_allow_ips,
)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_dev() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -60,6 +61,7 @@ def test_dev_package() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -96,6 +98,8 @@ def test_dev_args() -> None:
"--app",
"api",
"--no-proxy-headers",
"--reload-dirs",
"api,config",
],
)
assert result.exit_code == 0, result.output
Expand All @@ -109,6 +113,10 @@ def test_dev_args() -> None:
"workers": None,
"root_path": "/api",
"proxy_headers": False,
"reload_dirs": [
"api",
"config",
],
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -139,6 +147,7 @@ def test_dev_env_vars() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -176,6 +185,7 @@ def test_dev_env_vars_and_args() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -204,6 +214,7 @@ def test_run() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand All @@ -230,6 +241,7 @@ def test_run_trust_proxy() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": "*",
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -276,6 +288,7 @@ def test_run_args() -> None:
"workers": 2,
"root_path": "/api",
"proxy_headers": False,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -307,6 +320,7 @@ def test_run_env_vars() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -340,6 +354,7 @@ def test_run_env_vars_and_args() -> None:
"workers": None,
"root_path": "",
"proxy_headers": True,
"reload_dirs": None,
"forwarded_allow_ips": None,
"log_config": get_uvicorn_log_config(),
}
Expand Down Expand Up @@ -375,6 +390,7 @@ def test_dev_help() -> None:
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
assert "directories to watch for changes in." in result.output


def test_run_help() -> None:
Expand All @@ -396,6 +412,7 @@ def test_run_help() -> None:
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
assert "directories to watch for changes in." not in result.output


def test_callback_help() -> None:
Expand Down Expand Up @@ -426,6 +443,7 @@ def test_dev_with_import_string() -> None:
"reload": True,
"workers": None,
"root_path": "",
"reload_dirs": None,
"proxy_headers": True,
"log_config": get_uvicorn_log_config(),
}
Expand All @@ -447,6 +465,7 @@ def test_run_with_import_string() -> None:
"reload": False,
"workers": None,
"root_path": "",
"reload_dirs": None,
"proxy_headers": True,
"log_config": get_uvicorn_log_config(),
}
Expand Down