Improve documentation and modernize type hints
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""CLI entry point for rp — rich print files beautifully."""
|
||||
"""CLI entry point for rp."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
@@ -22,6 +22,11 @@ app = typer.Typer(
|
||||
|
||||
|
||||
def version_callback(value: bool) -> None:
|
||||
"""Print version information and exit.
|
||||
|
||||
Args:
|
||||
value: Flag value from typer callback.
|
||||
"""
|
||||
if value:
|
||||
console = Console()
|
||||
console.print(f"Rich Print (rp) {__version__}")
|
||||
@@ -33,11 +38,11 @@ def version_callback(value: bool) -> None:
|
||||
@app.command()
|
||||
def main(
|
||||
file: Annotated[
|
||||
Optional[Path],
|
||||
Path | None,
|
||||
typer.Argument(help="File to rich-print. Use '-' or omit to read from stdin."),
|
||||
] = None,
|
||||
file_type: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(
|
||||
"--type", "-t", help="Force file type (e.g. json, python, markdown)."
|
||||
),
|
||||
@@ -47,21 +52,21 @@ def main(
|
||||
typer.Option("--theme", help="Pygments color theme."),
|
||||
] = "monokai",
|
||||
line_numbers: Annotated[
|
||||
Optional[bool],
|
||||
bool | None,
|
||||
typer.Option(
|
||||
"--line-numbers/--no-line-numbers",
|
||||
help="Show line numbers. Default: auto.",
|
||||
),
|
||||
] = None,
|
||||
pager: Annotated[
|
||||
Optional[bool],
|
||||
bool | None,
|
||||
typer.Option(
|
||||
"--pager/--no-pager",
|
||||
help="Use pager for output. Default: auto-detect.",
|
||||
),
|
||||
] = None,
|
||||
version: Annotated[
|
||||
Optional[bool],
|
||||
bool | None,
|
||||
typer.Option(
|
||||
"--version",
|
||||
"-v",
|
||||
@@ -71,7 +76,16 @@ def main(
|
||||
),
|
||||
] = None,
|
||||
) -> None:
|
||||
"""Rich print files beautifully in your terminal."""
|
||||
"""Render a file or stdin input in the terminal.
|
||||
|
||||
Args:
|
||||
file: File to rich-print. Use '-' or omit to read from stdin.
|
||||
file_type: Force file type (e.g. json, python, markdown).
|
||||
theme: Pygments color theme.
|
||||
line_numbers: Show line numbers. Default: auto.
|
||||
pager: Use pager for output. Default: auto-detect.
|
||||
version: Show version and exit.
|
||||
"""
|
||||
console = Console()
|
||||
|
||||
if file is None or str(file) == "-":
|
||||
|
||||
Reference in New Issue
Block a user