Add opt-in debug logging across the CLI pipeline
Thread RP_DEBUG-driven logging through input, detection, rendering, and pager decisions so CLI behavior is inspectable without polluting stdout. Add focused coverage for debug wiring, env parsing, and stderr-only output.
This commit is contained in:
@@ -10,6 +10,7 @@ import typer
|
||||
from rich.console import Console
|
||||
|
||||
from rp import __author__, __license__, __version__
|
||||
from rp.debug import env_debug_enabled, log_debug, make_debug_logger
|
||||
from rp.detect import detect_type
|
||||
from rp.render import RenderOptions, render
|
||||
|
||||
@@ -95,13 +96,16 @@ def main(
|
||||
version: Show version and exit.
|
||||
"""
|
||||
console = Console()
|
||||
debug = make_debug_logger(Console(stderr=True), env_debug_enabled())
|
||||
|
||||
if file is None or str(file) == "-":
|
||||
log_debug(debug, "input: reading from stdin")
|
||||
if sys.stdin.isatty():
|
||||
console.print("[dim]Reading from stdin. Press Ctrl+D to end.[/dim]")
|
||||
content = sys.stdin.read()
|
||||
file_path = None
|
||||
else:
|
||||
log_debug(debug, f"input: reading file {str(file)!r}")
|
||||
if not file.exists():
|
||||
console.print(f"[red]Error:[/red] File not found: {file}")
|
||||
raise typer.Exit(code=1)
|
||||
@@ -127,12 +131,14 @@ def main(
|
||||
content=content,
|
||||
explicit_type=file_type,
|
||||
guess_content=guess_content,
|
||||
debug=debug,
|
||||
)
|
||||
|
||||
options = RenderOptions(
|
||||
theme=theme,
|
||||
line_numbers=line_numbers,
|
||||
pager=pager,
|
||||
debug=debug,
|
||||
)
|
||||
render(content, file_type, console, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user