mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 13:34:24 -05:00
feat(anki): force scan of single file/directory
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import typer
|
||||
@@ -11,7 +12,7 @@ from anki.typst_compiler import TypstCompiler
|
||||
cli = typer.Typer(name="typstar-anki")
|
||||
|
||||
|
||||
async def export_flashcards(root_dir, clear_cache, typst_cmd, anki_url, anki_key):
|
||||
async def export_flashcards(root_dir, force_scan, clear_cache, typst_cmd, anki_url, anki_key):
|
||||
parser = FlashcardParser()
|
||||
compiler = TypstCompiler(root_dir, typst_cmd)
|
||||
api = AnkiConnectApi(anki_url, anki_key)
|
||||
@@ -19,7 +20,7 @@ async def export_flashcards(root_dir, clear_cache, typst_cmd, anki_url, anki_key
|
||||
# parse flashcards
|
||||
if clear_cache:
|
||||
parser.clear_file_hashes()
|
||||
flashcards = parser.parse_directory(root_dir)
|
||||
flashcards = parser.parse_directory(root_dir, force_scan)
|
||||
|
||||
# async typst compilation
|
||||
await compiler.compile_flashcards(flashcards)
|
||||
@@ -36,14 +37,16 @@ async def export_flashcards(root_dir, clear_cache, typst_cmd, anki_url, anki_key
|
||||
|
||||
@cli.command()
|
||||
def cmd(root_dir: Annotated[
|
||||
str, typer.Option(help="Directory scanned for flashcards and passed over to typst compile command")] = os.getcwd(),
|
||||
Path, typer.Option(help="Directory scanned for flashcards and passed over to typst compile command")] = os.getcwd(),
|
||||
force_scan: Annotated[Path, typer.Option(help="File/directory to scan for flashcards while ignoring stored "
|
||||
"file hashes (e.g. on preamble change)")] = None,
|
||||
clear_cache: Annotated[bool, typer.Option(help="Clear all stored file hashes (more aggressive than force-scan "
|
||||
"as it clears hashes regardless of their path)")] = False,
|
||||
typst_cmd: Annotated[str, typer.Option(help="Typst command used for flashcard compilation")] = "typst",
|
||||
clear_cache: Annotated[bool, typer.Option(help="Clear stored file hashes and force compilation and "
|
||||
"push of all flashcards (e.g. on preamble change)")] = False,
|
||||
anki_url: Annotated[str, typer.Option(help="Url for Anki-Connect")] = "http://127.0.0.1:8765",
|
||||
anki_key: Annotated[str, typer.Option(help="Api key for Anki-Connect")] = None,
|
||||
):
|
||||
asyncio.run(export_flashcards(root_dir, clear_cache, typst_cmd, anki_url, anki_key))
|
||||
asyncio.run(export_flashcards(root_dir, force_scan, clear_cache, typst_cmd, anki_url, anki_key))
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user