Skip to content

Commit 36e900a

Browse files
authored
Ensure CLI prompt history directory and file exist before usage (#1707)
Co-authored-by: Zac <2215540+zboyles@users.noreply.github.com>
1 parent d211306 commit 36e900a

File tree

1 file changed

+4
-0
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+4
-0
lines changed

pydantic_ai_slim/pydantic_ai/_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def cli(args_list: Sequence[str] | None = None, *, prog_name: str = 'pai') -> in
203203
pass
204204
return 0
205205

206+
# Ensure the history directory and file exist
207+
PROMPT_HISTORY_PATH.parent.mkdir(parents=True, exist_ok=True)
208+
PROMPT_HISTORY_PATH.touch(exist_ok=True)
209+
206210
# doing this instead of `PromptSession[Any](history=` allows mocking of PromptSession in tests
207211
session: PromptSession[Any] = PromptSession(history=FileHistory(str(PROMPT_HISTORY_PATH)))
208212
try:

0 commit comments

Comments
 (0)