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
9 changes: 9 additions & 0 deletions src/sqlfmt/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def _format_one(path: Path, mode: Mode) -> SqlFormatResult:
Runs format_string on the contents of a single file (found at path). Handles
potential user errors in formatted code, and returns a SqlfmtResult
"""
if mode.verbose:
from sqlfmt.report import display_output

try:
display_path = path.relative_to(Path.cwd())
except ValueError:
display_path = path
display_output(f"Reading {display_path}")

source, encoding, utf_bom = _read_path_or_stdin(path, mode)
try:
formatted = format_string(source, mode)
Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,18 @@ def test_config_does_not_exist(
assert results.exit_code == 2
assert "Error: Invalid value for '--config'" in results.stderr
assert "does not exist" in results.stderr


def test_verbose_logging(sqlfmt_runner: CliRunner, preformatted_dir: Path) -> None:
# Use single-process mode to ensure verbose output is captured by CliRunner
args = f"{preformatted_dir.as_posix()} --verbose --check --no-progressbar --single-process"
results = sqlfmt_runner.invoke(sqlfmt_main, args=args)
assert results.exit_code == 0
# Verbose mode should print each file being processed
assert "Reading" in results.stderr
# Should see at least one file path in the output
sql_files = list(preformatted_dir.glob("*.sql"))
assert len(sql_files) > 0
# Check that at least one file path appears in verbose output
file_found = any(f.name in results.stderr for f in sql_files)
assert file_found, f"No file paths found in verbose output: {results.stderr}"