Verified Commit 205a9f3f authored by Jakob Moser's avatar Jakob Moser
Browse files

Move convert function to converter

parent 6cd9c17d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
from coliverter.app import app
from coliverter.convert import convert
+0 −39
Original line number Diff line number Diff line
from pathlib import Path
from typing import Annotated

import typer

from coliverter.FileFormat import FileFormat

app = typer.Typer()


@app.command()
def main(
    markdown_path: Annotated[
        Path | None,
        typer.Argument(
            help="Path to the input Markdown file. If None, read Markdown from STDIN."
        ),
    ] = None,
    output_path: Annotated[
        Path | None,
        typer.Argument(
            help="Path to the output file. If None, write output to STDOUT."
        ),
    ] = None,
    file_format: Annotated[
        FileFormat | None,
        typer.Option(
            help="Format of the output file. If None, infer from extension in output path. If inferring is not possible, default to html."
        ),
    ] = None,
) -> None:
    """
    Convert Markdown files into other formats, using the organization identity of Fachschaft Computerlinguistik.
    """
    if file_format is None:
        try:
            file_format = FileFormat[output_path.suffix if output_path else None]
        except KeyError:
            file_format = FileFormat.HTML

    # TODO Implement this
    print(markdown_path, output_path, file_format)
+41 −0
Original line number Diff line number Diff line
from pathlib import Path
from typing import Annotated

import typer

from coliverter.FileFormat import FileFormat
from coliverter.app import app


@app.command()
def convert(
    markdown_path: Annotated[
        Path | None,
        typer.Argument(
            help="Path to the input Markdown file. If None, read Markdown from STDIN."
        ),
    ] = None,
    output_path: Annotated[
        Path | None,
        typer.Argument(
            help="Path to the output file. If None, write output to STDOUT."
        ),
    ] = None,
    file_format: Annotated[
        FileFormat | None,
        typer.Option(
            help="Format of the output file. If None, infer from extension in output path. If inferring is not possible, default to html."
        ),
    ] = None,
) -> None:
    """
    Convert Markdown files into other formats, using the organization identity of Fachschaft Computerlinguistik.
    """
    if file_format is None:
        try:
            file_format = FileFormat[output_path.suffix if output_path else None]
        except KeyError:
            file_format = FileFormat.HTML

    # TODO Implement this
    print(markdown_path, output_path, file_format)