Skip to content

Commit 188f251

Browse files
committed
Fixed FileNotFoundError which occurred when running 'history --clear' and no history file existed.
1 parent da203d2 commit 188f251

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Fixed bug where setting `always_show_hint=True` did not show a hint when completing `Settables`
44
* Fixed bug in editor detection logic on Linux systems that do not have `which`
55
* Fixed bug in table creator where column headers with tabs would result in an incorrect width calculation
6+
* Fixed `FileNotFoundError` which occurred when running `history --clear` and no history file existed.
67
* Enhancements
78
* Added `silent_startup_script` option to `cmd2.Cmd.__init__()`. If `True`, then the startup script's
89
output will be suppressed. Anything written to stderr will still display.

cmd2/cmd2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3989,7 +3989,10 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
39893989
self.history.clear()
39903990

39913991
if self.persistent_history_file:
3992-
os.remove(self.persistent_history_file)
3992+
try:
3993+
os.remove(self.persistent_history_file)
3994+
except FileNotFoundError:
3995+
pass
39933996

39943997
if rl_type != RlType.NONE:
39953998
readline.clear_history()

0 commit comments

Comments
 (0)