diff --git a/pyproject.toml b/pyproject.toml index 55f63e4..dda049a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,7 @@ max-complexity = 10 convention = "google" [tool.ruff.lint.pylint] -max-args = 6 +max-args = 8 [tool.ruff.lint.per-file-ignores] "tests/**/*.py" = [ diff --git a/src/dbt_score/cli.py b/src/dbt_score/cli.py index c98b95d..cf315e8 100644 --- a/src/dbt_score/cli.py +++ b/src/dbt_score/cli.py @@ -1,5 +1,6 @@ """CLI interface.""" +import logging from pathlib import Path from typing import Final, Literal @@ -12,6 +13,8 @@ from dbt_score.parse import dbt_parse, get_default_manifest_path from dbt_score.rule_catalog import display_catalog +logger = logging.getLogger(__name__) + BANNER: Final[str] = r""" __ __ __ ____/ // /_ / /_ _____ _____ ____ _____ ___ @@ -75,7 +78,9 @@ def cli() -> None: is_flag=True, default=False, ) +@click.pass_context def lint( + ctx: click.Context, format: Literal["plain", "manifest"], select: tuple[str], namespace: list[str], @@ -101,7 +106,14 @@ def lint( if run_dbt_parse: dbt_parse() - lint_dbt_project(manifest_path=manifest, config=config, format=format) + try: + lint_dbt_project(manifest_path=manifest, config=config, format=format) + except FileNotFoundError: + logger.error( + "dbt's manifest.json could not be found. If you're in a dbt project, be " + "sure to run 'dbt parse' first, or use the option '--run-dbt-parse'." + ) + ctx.exit(2) @cli.command(name="list") diff --git a/tests/formatters/test_manifest_formatter.py b/tests/formatters/test_manifest_formatter.py index 98ca453..7403e5f 100644 --- a/tests/formatters/test_manifest_formatter.py +++ b/tests/formatters/test_manifest_formatter.py @@ -27,7 +27,7 @@ def test_manifest_formatter_model( assert stdout == "" -def test_human_readable_formatter_project( # noqa: PLR0913 +def test_manifest_formatter_project( capsys, manifest_loader, model1, diff --git a/tests/test_cli.py b/tests/test_cli.py index f22f7c7..499d01d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,7 +2,6 @@ from unittest.mock import patch -import pytest from click.testing import CliRunner from dbt_score.cli import lint @@ -25,18 +24,21 @@ def test_lint_existing_manifest(manifest_path): assert result.exit_code == 0 -def test_lint_non_existing_manifest(): +def test_lint_non_existing_manifest(caplog): """Test lint with a non-existing manifest.""" runner = CliRunner() # Provide manifest in command line - with pytest.raises(FileNotFoundError): - with patch("dbt_score.cli.Config._load_toml_file"): - runner.invoke( - lint, ["--manifest", "fake_manifest.json"], catch_exceptions=False - ) + with patch("dbt_score.cli.Config._load_toml_file"): + result = runner.invoke( + lint, ["--manifest", "fake_manifest.json"], catch_exceptions=False + ) + assert result.exit_code == 2 + assert "dbt's manifest.json could not be found" in caplog.text # Use default manifest path - with pytest.raises(FileNotFoundError): - with patch("dbt_score.cli.Config._load_toml_file"): - runner.invoke(lint, catch_exceptions=False) + with patch("dbt_score.cli.Config._load_toml_file"): + result = runner.invoke(lint, catch_exceptions=False) + + assert result.exit_code == 2 + assert "dbt's manifest.json could not be found" in caplog.text