owenrusk.dev

casebench

test cases straight onto the board.

git clone https://owenrusk.dev/casebench.git

commit cdb46586e2fedfd726393d22d039620c4ad63c9d
parent acdd9af863691b9e6adf5e8d345bda9d305b559b
author Owen Rusk <owen@papermothgames.com>
date   2026-08-25 15:03:40 -0500
note: -f - reads the note from stdin
casebench/cli.py+8-2
tests/test_commands.py+14-0
diff --git a/casebench/cli.py b/casebench/cli.py
index 24e4290..51a2382 100644
--- a/casebench/cli.py
+++ b/casebench/cli.py
@@ -25,7 +25,7 @@ def parser() -> argparse.ArgumentParser:
     note.add_argument("case")
     words = note.add_mutually_exclusive_group(required=True)
     words.add_argument("text", nargs="?")
-    words.add_argument("-f", "--file", type=Path, help="read the note from a file")
+    words.add_argument("-f", "--file", help="read the note from a file; - for stdin")
     note.add_argument("--item", help="the item to write on; the case's title if left out")
     boards(note)
     note.set_defaults(run=run_note)
@@ -118,7 +118,13 @@ def run_put(store: Store, args: argparse.Namespace) -> None:
 
 
 def run_note(store: Store, args: argparse.Namespace) -> None:
-    text = (args.file.read_text(encoding="utf-8") if args.file else args.text).rstrip()
+    if args.file is None:
+        text = args.text
+    elif args.file == "-":
+        text = sys.stdin.read()
+    else:
+        text = Path(args.file).read_text(encoding="utf-8")
+    text = text.rstrip()
     if not text:
         raise Fail("nothing to write")
     players = targets(store, args)
diff --git a/tests/test_commands.py b/tests/test_commands.py
index b3cd77a..2f1a5a4 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1,4 +1,7 @@
+import io
+import tempfile
 import unittest
+from unittest import mock
 
 from casebench.memstore import MemStore
 
@@ -74,6 +77,17 @@ class NoteTest(unittest.TestCase):
         run(self.store, "note", "test-lost-umbrella", "same number", "--item", "ticket", "--player", "owen")
         self.assertEqual(self.store.notes(self.owen, "test-lost-umbrella"), [("ticket", "same number")])
 
+    def test_from_a_file_and_stdin(self):
+        with tempfile.NamedTemporaryFile("w", suffix=".md", delete_on_close=False) as f:
+            f.write("**114**\n")
+            f.close()
+            run(self.store, "note", "test-lost-umbrella", "-f", f.name, "--item", "ticket", "--player", "owen")
+        with mock.patch("sys.stdin", io.StringIO("from stdin\n")):
+            run(self.store, "note", "test-lost-umbrella", "-f", "-", "--player", "owen")
+        self.assertEqual(
+            self.store.notes(self.owen, "test-lost-umbrella"), [("ticket", "**114**"), (None, "from stdin")]
+        )
+
     def test_no_such_item(self):
         code, _, err = run(self.store, "note", "test-lost-umbrella", "x", "--item", "hat", "--player", "owen")
         self.assertEqual(code, 1)