41 lines
1.8 KiB
Python
41 lines
1.8 KiB
Python
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) |