summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml2
-rw-r--r--cmd2/cmd2.py57
2 files changed, 30 insertions, 29 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f8aedfb2..1e037344 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -39,7 +39,7 @@ jobs:
- name: Install python prerequisites
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
- pip install -Ur pip install flake8 nox
+ pip install -U pip flake8 nox
python setup.py develop
- name: Lint
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 51670235..66b9055f 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -4001,36 +4001,11 @@ class Cmd(cmd.Cmd):
readline.clear_history()
return
- # If an argument was supplied, then retrieve partial contents of the history
- cowardly_refuse_to_run = False
- if args.arg:
- # If a character indicating a slice is present, retrieve
- # a slice of the history
- arg = args.arg
- arg_is_int = False
- try:
- int(arg)
- arg_is_int = True
- except ValueError:
- pass
-
- if '..' in arg or ':' in arg:
- # Get a slice of history
- 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, args.all)
- else:
- 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.span(':', args.all)
+ # If an argument was supplied, then retrieve partial contents of the history, otherwise retrieve it all
+ history = self._get_history(args)
if args.run:
- if cowardly_refuse_to_run:
+ if not args.arg:
self.perror("Cowardly refusing to run all previously entered commands.")
self.perror("If this is what you want to do, specify '1:' as the range of history.")
else:
@@ -4070,6 +4045,32 @@ class Cmd(cmd.Cmd):
for hi in history:
self.poutput(hi.pr(script=args.script, expanded=args.expanded, verbose=args.verbose))
+ def _get_history(self, args: argparse.Namespace) -> List[HistoryItem]:
+ """If an argument was supplied, then retrieve partial contents of the history; otherwise retrieve entire history."""
+ if args.arg:
+ # If a character indicating a slice is present, retrieve a slice of the history
+ arg = args.arg
+ arg_is_int = False
+ try:
+ int(arg)
+ arg_is_int = True
+ except ValueError:
+ pass
+
+ if '..' in arg or ':' in arg:
+ # Get a slice of history
+ 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, args.all)
+ else:
+ history = self.history.str_search(arg, args.all)
+ else:
+ # Get a copy of the history so it doesn't get mutated while we are using it
+ history = self.history.span(':', args.all)
+ return history
+
def _initialize_history(self, hist_file):
"""Initialize history using history related attributes