diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-13 12:48:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-13 12:48:28 -0400 |
commit | 04340d17da90002e3c521bf3339d28b5ef9acfbd (patch) | |
tree | 1262c76878a5202366fe284b734e5657723ac3cd | |
parent | 30a3b66e8bc9f2fc65f5ff763841438ecda3a362 (diff) | |
parent | dd9717efb9cbbd2f791057742e6f7323b317d46b (diff) | |
download | cmd2-git-04340d17da90002e3c521bf3339d28b5ef9acfbd.tar.gz |
Merge pull request #191 from python-cmd2/insensitive_completion
Added support for case-insensitive tab-completion of cmd2 command names
-rw-r--r-- | CHANGES.md | 2 | ||||
-rwxr-xr-x | cmd2.py | 6 | ||||
-rw-r--r-- | tests/test_completion.py | 22 |
3 files changed, 29 insertions, 1 deletions
@@ -11,6 +11,8 @@ News * <Ctrl>+D now properly quits when case-sensitive command parsing is enabled * Fixed some pyperclip clipboard interaction bugs on Linux * Fixed some timing bugs when running unit tests in parallel by using monkeypatch +* Enhancements + * Enhanced tab-completion of cmd2 command names to support case-insensitive completion 0.7.5 ----- @@ -582,8 +582,12 @@ class Cmd(cmd.Cmd): # noinspection PyMethodOverriding def completenames(self, text, line, begidx, endidx): """Override of cmd2 method which completes command names both for command completion and help.""" + command = text + if self.case_insensitive: + command = text.lower() + # Call super class method. Need to do it this way for Python 2 and 3 compatibility - cmd_completion = cmd.Cmd.completenames(self, text) + cmd_completion = cmd.Cmd.completenames(self, command) # If we are completing the initial command name and get exactly 1 result and are at end of line, add a space if begidx == 0 and len(cmd_completion) == 1 and endidx == len(line): diff --git a/tests/test_completion.py b/tests/test_completion.py index a219a904..efc32986 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -20,6 +20,12 @@ def cmd2_app(): c = cmd2.Cmd() return c +@pytest.fixture +def cs_app(): + cmd2.Cmd.case_insensitive = False + c = cmd2.Cmd() + return c + def test_cmd2_command_completion_single_end(cmd2_app): text = 'he' @@ -29,6 +35,22 @@ def test_cmd2_command_completion_single_end(cmd2_app): # It is at end of line, so extra space is present assert cmd2_app.completenames(text, line, begidx, endidx) == ['help '] +def test_cmd2_command_completion_is_case_insensitive_by_default(cmd2_app): + text = 'HE' + line = 'HE' + endidx = len(line) + begidx = endidx - len(text) + # It is at end of line, so extra space is present + assert cmd2_app.completenames(text, line, begidx, endidx) == ['help '] + +def test_cmd2_case_sensitive_command_completion(cs_app): + text = 'HE' + line = 'HE' + endidx = len(line) + begidx = endidx - len(text) + # It is at end of line, so extra space is present + assert cs_app.completenames(text, line, begidx, endidx) == [] + def test_cmd2_command_completion_single_mid(cmd2_app): text = 'he' line = 'he' |