summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-09 00:41:29 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-09 00:41:29 -0500
commit7d4cbc4f2fcfe1cc2375146b572301478f1c1779 (patch)
treed2860b5406be751460bf26153b82c22b67b3e7c0 /examples
parent8209a5ada836355148496a543f14179a545ee79c (diff)
downloadcmd2-git-7d4cbc4f2fcfe1cc2375146b572301478f1c1779.tar.gz
Make sure pexpect uses same version of Python to spawn persistent history example
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/persistent_history.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/examples/persistent_history.py b/examples/persistent_history.py
index e3f646bf..e1874212 100755
--- a/examples/persistent_history.py
+++ b/examples/persistent_history.py
@@ -10,14 +10,24 @@ import cmd2
class Cmd2PersistentHistory(cmd2.Cmd):
"""Basic example of how to enable persistent readline history within your cmd2 app."""
- def __init__(self):
- """"""
- cmd2.Cmd.__init__(self, persistent_history_file='~/.persistent_history.cmd2', persistent_history_length=500)
+ def __init__(self, hist_file):
+ """Configure the app to load persistent readline history from a file.
+
+ :param hist_file: file to load readline history from at start and write it to at end
+ """
+ cmd2.Cmd.__init__(self, persistent_history_file=hist_file, persistent_history_length=500)
+ self.allow_cli_args = False
self.prompt = 'ph> '
# ... your class code here ...
if __name__ == '__main__':
- app = Cmd2PersistentHistory()
+ import sys
+
+ history_file = '~/.persistent_history.cmd2'
+ if len(sys.argv) > 1:
+ history_file = sys.argv[1]
+
+ app = Cmd2PersistentHistory(hist_file=history_file)
app.cmdloop()