Skip to content
Draft
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
19 changes: 19 additions & 0 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typer
from pydantic import ValidationError
from rich import print
from rich.syntax import Syntax
from rich.tree import Tree

from fastapi_cli.config import FastAPIConfig
Expand Down Expand Up @@ -215,6 +216,24 @@ def _run(
toolkit.print(f" • Module: {mod_source_desc}")
toolkit.print(f" • App name: {app_source_desc}")

if import_data.module_config_source == "auto-discovery":
toolkit.print_line()
toolkit.print(
"You can configure an entrypoint in [blue]pyproject.toml[/] for this app with:",
tag="tip",
)
toolkit.print_line()
toolkit.print(
Syntax(
(
"[tool.fastapi]\n"
f'entrypoint = "{import_data.module_data.module_import_str}:{import_data.app_name}"'
),
"toml",
theme="ansi_light",
)
)

url = f"http://{host}:{port}"
url_docs = f"{url}/docs"

Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_dev() -> None:
assert "Configuration sources:" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting development server 🚀" in result.output
assert "Server started at http://127.0.0.1:8000" in result.output
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
Expand All @@ -64,6 +65,9 @@ def test_dev_no_args_auto_discovery() -> None:
assert "Using import string: main:app" in result.output
assert "Configuration sources:" in result.output
assert "Import string: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" in result.output
assert "[tool.fastapi]" in result.output
assert 'entrypoint = "main:app"' in result.output


def test_dev_package() -> None:
Expand All @@ -88,6 +92,7 @@ def test_dev_package() -> None:
assert "Using import string: nested_package.package:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting development server 🚀" in result.output
assert "Server started at http://127.0.0.1:8000" in result.output
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
Expand Down Expand Up @@ -140,6 +145,7 @@ def test_dev_args() -> None:
assert "Using import string: single_file_app:api" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: --app CLI option" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting development server 🚀" in result.output
assert "Server started at http://192.168.0.2:8080" in result.output
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
Expand Down Expand Up @@ -173,6 +179,7 @@ def test_dev_env_vars() -> None:
assert "Using import string: single_file_app:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting development server 🚀" in result.output
assert "Server started at http://127.0.0.1:8111" in result.output
assert "Documentation at http://127.0.0.1:8111/docs" in result.output
Expand Down Expand Up @@ -213,6 +220,7 @@ def test_dev_env_vars_and_args() -> None:
assert "Using import string: single_file_app:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting development server 🚀" in result.output
assert "Server started at http://127.0.0.1:8080" in result.output
assert "Documentation at http://127.0.0.1:8080/docs" in result.output
Expand Down Expand Up @@ -261,6 +269,7 @@ def test_run() -> None:
assert "Using import string: single_file_app:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting production server 🚀" in result.output
assert "Server started at http://0.0.0.0:8000" in result.output
assert "Documentation at http://0.0.0.0:8000/docs" in result.output
Expand Down Expand Up @@ -338,6 +347,7 @@ def test_run_args() -> None:
assert "Using import string: single_file_app:api" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: --app CLI option" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting production server 🚀" in result.output
assert "Server started at http://192.168.0.2:8080" in result.output
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
Expand Down Expand Up @@ -371,6 +381,7 @@ def test_run_env_vars() -> None:
assert "Using import string: single_file_app:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting production server 🚀" in result.output
assert "Server started at http://0.0.0.0:8111" in result.output
assert "Documentation at http://0.0.0.0:8111/docs" in result.output
Expand Down Expand Up @@ -407,6 +418,7 @@ def test_run_env_vars_and_args() -> None:
assert "Using import string: single_file_app:app" in result.output
assert "Module: path CLI argument" in result.output
assert "App name: auto-discovery" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output
assert "Starting production server 🚀" in result.output
assert "Server started at http://0.0.0.0:8080" in result.output
assert "Documentation at http://0.0.0.0:8080/docs" in result.output
Expand Down Expand Up @@ -520,6 +532,7 @@ def test_dev_with_import_string() -> None:
}
assert "Using import string: single_file_app:api" in result.output
assert "Import string: --entrypoint CLI option" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output


def test_run_with_import_string() -> None:
Expand All @@ -543,6 +556,7 @@ def test_run_with_import_string() -> None:
}
assert "Using import string: single_file_app:app" in result.output
assert "Import string: --entrypoint CLI option" in result.output
assert "You can configure an entrypoint in pyproject.toml" not in result.output


def test_script() -> None:
Expand Down
Loading