casebench
test cases straight onto the board.
git clone https://owenrusk.dev/casebench.git
commit cd2587571b8f4cdbc6960e10ff951e363fd789ec parent 206a88464e78e7cc470254d25607b7ee82b62670 author Owen Rusk <owen@papermothgames.com> date 2025-04-03 11:56:40 -0500
note: notes on items too
| casebench/cli.py | +5 | -2 |
| casebench/db.py | +12 | -2 |
diff --git a/casebench/cli.py b/casebench/cli.py index 5c8b704..51297ba 100644 --- a/casebench/cli.py +++ b/casebench/cli.py @@ -25,6 +25,7 @@ def main(argv: list[str] | None = None) -> int: note.add_argument("case") note.add_argument("text") note.add_argument("--player", required=True) + note.add_argument("--item", help="the item to write on; the case's title if left out") note.set_defaults(run=run_note) args = parser.parse_args(argv) @@ -61,5 +62,7 @@ def run_note(conn: psycopg.Connection, args: argparse.Namespace) -> None: who = player(conn, args.player) if db.source(conn, who, args.case) is None: raise Fail(f"{args.player} doesn't have {args.case}")- db.note(conn, who, args.case, args.text)- print(f"{args.player}: noted {args.case}")+ if args.item and args.item not in db.items(conn, who, args.case): + raise Fail(f"{args.case} has no item {args.item}") + db.note(conn, who, args.case, args.item, args.text) + print(f"{args.player}: noted {args.case}" + (f" / {args.item}" if args.item else "")) diff --git a/casebench/db.py b/casebench/db.py index 1a1a03b..23357ff 100644 --- a/casebench/db.py +++ b/casebench/db.py @@ -36,8 +36,18 @@ def put(conn: psycopg.Connection, player: str, case: Case) -> None: )-def note(conn: psycopg.Connection, player: str, case_id: str, text: str) -> None:+def items(conn: psycopg.Connection, player: str, case_id: str) -> list[str]: + rows = conn.execute( + "select item_id from board_items where player_id = %s and case_id = %s order by position", + (player, case_id), + ).fetchall() + return [row[0] for row in rows] + + +def note(conn: psycopg.Connection, player: str, case_id: str, item_id: str | None, text: str) -> None: + # no item: the note goes under the case's title. conn.execute(- "insert into board_notes (player_id, case_id, body) values (%s, %s, %s)", (player, case_id, text)+ "insert into board_notes (player_id, case_id, item_id, body) values (%s, %s, %s, %s)", + (player, case_id, item_id, text), ) conn.commit()