summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py14
-rwxr-xr-xexamples/tab_autocompletion.py6
-rw-r--r--tests/test_completion.py10
3 files changed, 15 insertions, 15 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index d44e6df4..e5c2ac44 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -724,7 +724,7 @@ class Cmd(cmd.Cmd):
# noinspection PyUnresolvedReferences
readline.rl.mode._display_completions = self._display_matches_pyreadline
- def _tokens_for_completion(self, line: str, begidx: int, endidx: int) -> Tuple[List[str], List[str]]:
+ def tokens_for_completion(self, line: str, begidx: int, endidx: int) -> Tuple[List[str], List[str]]:
"""
Used by tab completion functions to get all tokens through the one being completed
:param line: the current input line with leading whitespace removed
@@ -938,7 +938,7 @@ class Cmd(cmd.Cmd):
:return: a list of possible tab completions
"""
# Get all tokens through the one being completed
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
if not tokens:
return []
@@ -980,7 +980,7 @@ class Cmd(cmd.Cmd):
:return: a list of possible tab completions
"""
# Get all tokens through the one being completed
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
if not tokens:
return []
@@ -1192,7 +1192,7 @@ class Cmd(cmd.Cmd):
# Get all tokens through the one being completed. We want the raw tokens
# so we can tell if redirection strings are quoted and ignore them.
- _, raw_tokens = self._tokens_for_completion(line, begidx, endidx)
+ _, raw_tokens = self.tokens_for_completion(line, begidx, endidx)
if not raw_tokens:
return []
@@ -1397,7 +1397,7 @@ class Cmd(cmd.Cmd):
line = expanded_line
# Get all tokens through the one being completed
- tokens, raw_tokens = self._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = self.tokens_for_completion(line, begidx, endidx)
# Check if we either had a parsing error or are trying to complete the command token
# The latter can happen if " or ' was entered as the command
@@ -1570,7 +1570,7 @@ class Cmd(cmd.Cmd):
"""Default completion function for argparse commands."""
completer = AutoCompleter(argparser, self)
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
if not tokens:
return []
@@ -2607,7 +2607,7 @@ class Cmd(cmd.Cmd):
"""Completes the subcommand argument of help"""
# Get all tokens through the one being completed
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
if not tokens:
return []
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py
index 4919eca8..8f27cb90 100755
--- a/examples/tab_autocompletion.py
+++ b/examples/tab_autocompletion.py
@@ -382,7 +382,7 @@ class TabCompleteExample(cmd2.Cmd):
self,
arg_choices=choices)
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
results = completer.complete_command(tokens, text, line, begidx, endidx)
return results
@@ -443,7 +443,7 @@ class TabCompleteExample(cmd2.Cmd):
# Demonstrates a custom completion function that does more with the command line than is
# allowed by the standard completion functions
def _filter_episodes(self, text, line, begidx, endidx, show_db, user_lib):
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
show_id = tokens[3]
if show_id:
if show_id in show_db:
@@ -530,7 +530,7 @@ class TabCompleteExample(cmd2.Cmd):
self,
subcmd_args_lookup=library_subcommand_groups)
- tokens, _ = self._tokens_for_completion(line, begidx, endidx)
+ tokens, _ = self.tokens_for_completion(line, begidx, endidx)
results = completer.complete_command(tokens, text, line, begidx, endidx)
return results
diff --git a/tests/test_completion.py b/tests/test_completion.py
index d5d30e51..9157ce84 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -658,7 +658,7 @@ def test_tokens_for_completion_quoted(cmd2_app):
expected_tokens = ['list_food', 'Pi', '']
expected_raw_tokens = ['list_food', '"Pi"', '']
- tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -671,7 +671,7 @@ def test_tokens_for_completion_unclosed_quote(cmd2_app):
expected_tokens = ['list_food', 'Pi']
expected_raw_tokens = ['list_food', '"Pi']
- tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -685,7 +685,7 @@ def test_tokens_for_completion_redirect(cmd2_app):
expected_tokens = ['command', '|', '<', '>>', 'file']
expected_raw_tokens = ['command', '|', '<', '>>', 'file']
- tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -699,7 +699,7 @@ def test_tokens_for_completion_quoted_redirect(cmd2_app):
expected_tokens = ['command', '>file']
expected_raw_tokens = ['command', '">file']
- tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -713,7 +713,7 @@ def test_tokens_for_completion_redirect_off(cmd2_app):
expected_tokens = ['command', '>file']
expected_raw_tokens = ['command', '>file']
- tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens