diff --git a/.gitignore b/.gitignore index 59d5265..e905b88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ build *.egg-info +*/__pycache__ +__pycache__ diff --git a/term_color_md/__init__.py b/print_md/__init__.py similarity index 81% rename from term_color_md/__init__.py rename to print_md/__init__.py index 87740f8..7144d96 100644 --- a/term_color_md/__init__.py +++ b/print_md/__init__.py @@ -4,7 +4,10 @@ # # You should have received a copy of the GNU General Public License along with this program. If not, see . +import argparse import re +import sys + from termcolor import colored from pygments import highlight from pygments.lexers import get_lexer_by_name, TextLexer @@ -100,3 +103,30 @@ def render(text): return formatted_text + +def main() -> None: + """Command‑line entry point. + + The CLI accepts one or more file paths, reads each file, renders it via + :func:`render`, and prints the result to stdout. Files that cannot be + opened will emit an error on ``stderr`` but the program continues + processing subsequent files. + """ + + parser = argparse.ArgumentParser( + description="Render markdown files to the terminal with ANSI color." # pragma: no cover - trivial description + ) + parser.add_argument("files", nargs="+", help="Markdown files to render") + args = parser.parse_args() + + for path in args.files: + try: + with open(path, "r", encoding="utf-8") as f: + content = f.read() + # Render and print + sys.stdout.write(render(content)) + except Exception as exc: # pragma: no cover - error handling + sys.stderr.write(f"Error reading {path}: {exc}\n") + +if __name__ == "__main__": # pragma: no cover - used only when executed as script + main() diff --git a/pyproject.toml b/pyproject.toml index b1d31b7..f93963f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,9 +11,9 @@ build-backend = "setuptools.build_meta" # 2. Project metadata (replaces the `setup()` call) # ------------------------------------------------------------------ [project] -name = "term_color_md" +name = "print_md" version = "0.1" -description = "simple utilities to render markdon on the terminal" +description = "simple utilities to print markdown on the terminal colorfully" requires-python = ">=3.9" # Dependencies that your package needs at install‑time @@ -21,3 +21,6 @@ dependencies = [ "termcolor>=3.1.0", "pygments>=2.12", ] + +[project.scripts] +print_md = "print_md:main" diff --git a/term_color_md/__pycache__/__init__.cpython-311.pyc b/term_color_md/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 670c634..0000000 Binary files a/term_color_md/__pycache__/__init__.cpython-311.pyc and /dev/null differ