summaryrefslogtreecommitdiffstats
path: root/cli-project
diff options
context:
space:
mode:
Diffstat (limited to 'cli-project')
-rw-r--r--cli-project/flashcard_cli.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/cli-project/flashcard_cli.py b/cli-project/flashcard_cli.py
index 27a3a77..64a26b2 100644
--- a/cli-project/flashcard_cli.py
+++ b/cli-project/flashcard_cli.py
@@ -7,13 +7,19 @@ from flashcards import Session, SCHEDULERS
def cli():
pass
-def displayCard(card, index: int, random_flip: bool) -> None:
+def displayCard(card, index: int, prompt_mode: str) -> None:
click.echo(click.style(f"{index + 1} ===========================================================", fg="blue"))
- faces = [card.front, card.back]
-
- if random_flip:
- shuffle(faces)
+ match prompt_mode:
+ case "front":
+ faces = [card.front, card.back]
+ case "back":
+ faces = [card.back, card.front]
+ case "random":
+ faces = [card.front, card.back]
+ shuffle(faces)
+ case _:
+ raise Exception(f"Invalid prompt mode: {prompt_mode}")
click.echo(click.style(faces.pop(0), fg="yellow"))
input()
@@ -24,30 +30,30 @@ def displayCard(card, index: int, random_flip: bool) -> None:
@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):
+@click.option("--prompt", default="front", type=click.Choice(["front", "back", "random"], case_sensitive=False), help="Prompt using card front, back, or randomly choose")
+def practice(state_file, card_files, scheduler_name, count, prompt):
"""
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)
+ displayCard(card, i, prompt)
@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):
+@click.option("--prompt", default="front", type=click.Choice(["front", "back", "random"], case_sensitive=False), help="Prompt using card front, back, or randomly choose")
+def test(state_file, card_files, scheduler_name, count, prompt):
"""
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)
+ displayCard(card, i, prompt)
correct(click.confirm(click.style("Correct?", bold=True)))
if __name__ == '__main__':