Files
md-to-docx/src/__main__.py
Mikan bba1e8ca7e [AI]
MVP готов
2025-12-08 17:48:35 +03:00

41 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Optional
import typer
from pathlib import Path
from .core.converter import process_document
app = typer.Typer()
import logging
logger = logging.getLogger(__name__)
@app.command()
def convert(
input_dir: Path = typer.Option(..., "--input", "-i", help="Папка с исходниками"),
output_dir: Path = typer.Option(..., "--output", "-o", help="Папка для результата"),
style_config: Path = typer.Option("resources/style_config.yaml", "--style", "-s", help="Файл стилей"),
template: Optional[Path] = typer.Option(None, "--template", "-t", help="Шаблон .dotx"),
theme: Optional[str] = typer.Option(None, "--theme", "-T", help="Название темы (gost, academic...)"),
plugins_dir: Optional[Path] = typer.Option(None, "--plugins", "-p", help="Папка с плагинами"),
dry_run: bool = typer.Option(False, "--dry-run", help="Только показать, что будет сделано"),
quiet: bool = typer.Option(False, "--quiet", "-q", help="Не выводить логи"),
verbose: bool = typer.Option(False, "--verbose", "-v", help="Включить отладочные сообщения"),
):
if quiet:
log_level = logging.WARNING
elif verbose:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logging.basicConfig(level=log_level, format='%(levelname)s: %(message)s')
if dry_run:
logger.info("Режим --dry-run: файлы не будут созданы")
for doc_dir in input_dir.iterdir():
if doc_dir.is_dir() and (doc_dir / "document.md").exists():
logger.info(f"Будет обработан: {doc_dir.name}")
return
process_document(input_dir, output_dir, style_config, template, theme, plugins_dir)