diff options
Diffstat (limited to 'cli-project')
-rw-r--r-- | cli-project/flashcard_cli.py | 55 | ||||
-rw-r--r-- | cli-project/pyproject.toml | 19 |
2 files changed, 74 insertions, 0 deletions
diff --git a/cli-project/flashcard_cli.py b/cli-project/flashcard_cli.py new file mode 100644 index 0000000..27a3a77 --- /dev/null +++ b/cli-project/flashcard_cli.py @@ -0,0 +1,55 @@ +import click +from random import shuffle + +from flashcards import Session, SCHEDULERS + +@click.group() +def cli(): + pass + +def displayCard(card, index: int, random_flip: bool) -> None: + click.echo(click.style(f"{index + 1} ===========================================================", fg="blue")) + + faces = [card.front, card.back] + + if random_flip: + shuffle(faces) + + click.echo(click.style(faces.pop(0), fg="yellow")) + input() + click.echo(faces.pop(0)) + +@cli.command() +@click.argument("state_file", nargs=1, type=click.Path()) +@click.argument("card_files", nargs=-1, type=click.Path(exists=True)) +@click.option("--scheduler", "scheduler_name", default="brutal", type=click.Choice(SCHEDULERS, case_sensitive=False), help="Name of desired scheduler") +@click.option("--count", default=20, type=int, help="Number of cards to show during the session") +@click.option("--random_flip", is_flag=True, help="Prompt with card front or back randomly instead of always front") +def practice(state_file, card_files, scheduler_name, count, random_flip): + """ + Run a practice session with the specified scheduler, using the provided state and card files. + """ + session = Session(scheduler_name, card_files, state_file) + + for i, card in enumerate(session.practice(count)): + displayCard(card, i, random_flip) + +@cli.command() +@click.argument("state_file", nargs=1, type=click.Path()) +@click.argument("card_files", nargs=-1, type=click.Path(exists=True)) +@click.option("--scheduler", "scheduler_name", default="brutal", type=click.Choice(SCHEDULERS, case_sensitive=False), help="Name of desired scheduler") +@click.option("--count", default=20, type=int, help="Number of cards to show during the session") +@click.option("--random_flip", is_flag=True, help="Prompt with card front or back randomly instead of always front") +def test(state_file, card_files, scheduler_name, count, random_flip): + """ + Run a test session with the specified scheduler, using the provided state and card files. + """ + session = Session(scheduler_name, card_files, state_file) + + for i, (card, correct) in enumerate(session.test(count)): + displayCard(card, i, random_flip) + correct(click.confirm(click.style("Correct?", bold=True))) + +if __name__ == '__main__': + cli() + diff --git a/cli-project/pyproject.toml b/cli-project/pyproject.toml new file mode 100644 index 0000000..333c9cd --- /dev/null +++ b/cli-project/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "flashcards_cli" +authors = [ + {name = "Eddy Pedroni", email = "epedroni@pm.me"}, +] +description = "A CLI frontend for the flashcards library" +requires-python = ">=3.12" +dependencies = [ + "click", + "flashcards" +] +dynamic = ["version"] + +[project.scripts] +flashcard_cli = "flashcard_cli:cli" |