diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-27 15:45:34 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-27 15:45:34 -0400 |
commit | 9dd00461b22085d3f16b4cc178a222c30fe95d11 (patch) | |
tree | e1644047665caf1d15860be388510fe7b7b61d1a /cmd2/cmd2.py | |
parent | 916060bde828d8911ec2bbb4db54396212514481 (diff) | |
download | cmd2-git-9dd00461b22085d3f16b4cc178a222c30fe95d11.tar.gz |
Add the -a/--all flag to the history command for showing all commands including those persisted from previous sessions
Also:
- History class has been modified to keep track of the session start index
- History class span(), str_search(), and regex_search() methods now take an optional 2nd boolean parameter `include_persisted` which determines whether or not commands persisted from previous sessions should be included by default
- If a start index is manually specified, then it automatically includes the full search
- Updates unit tests
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index e4fe6efa..b13eb45b 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -345,8 +345,8 @@ class Cmd(cmd.Cmd): :param completekey: (optional) readline name of a completion key, default to Tab :param stdin: (optional) alternate input file object, if not specified, sys.stdin is used :param stdout: (optional) alternate output file object, if not specified, sys.stdout is used - :param persistent_history_file: (optional) file path to load a persistent readline history from - :param persistent_history_length: (optional) max number of lines which will be written to the history file + :param persistent_history_file: (optional) file path to load a persistent cmd2 command history from + :param persistent_history_length: (optional) max number of history items to write to the persistent history file :param startup_script: (optional) file path to a a script to load and execute at startup :param use_ipython: (optional) should the "ipy" command be included for an embedded IPython shell :param transcript_files: (optional) allows running transcript tests when allow_cli_args is False @@ -3337,6 +3337,8 @@ class Cmd(cmd.Cmd): history_format_group.add_argument('-v', '--verbose', action='store_true', help='display history and include expanded commands if they\n' 'differ from the typed command') + history_format_group.add_argument('-a', '--all', action='store_true', + help='display all commands, including ones persisted from previous sessions') history_arg_help = ("empty all history items\n" "a one history item by number\n" @@ -3389,18 +3391,18 @@ class Cmd(cmd.Cmd): if '..' in arg or ':' in arg: # Get a slice of history - history = self.history.span(arg) + history = self.history.span(arg, args.all) elif arg_is_int: history = [self.history.get(arg)] elif arg.startswith(r'/') and arg.endswith(r'/'): - history = self.history.regex_search(arg) + history = self.history.regex_search(arg, args.all) else: - history = self.history.str_search(arg) + history = self.history.str_search(arg, args.all) else: # If no arg given, then retrieve the entire history cowardly_refuse_to_run = True # Get a copy of the history so it doesn't get mutated while we are using it - history = self.history[:] + history = self.history.span(':', args.all) if args.run: if cowardly_refuse_to_run: @@ -3488,6 +3490,7 @@ class Cmd(cmd.Cmd): return self.history = history + self.history.start_session() self.persistent_history_file = hist_file # populate readline history |