summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-15 18:45:18 -0400
committerGitHub <noreply@github.com>2017-06-15 18:45:18 -0400
commita9f7c775dda166ae9f376d0eecd3cb9576ccef16 (patch)
tree28c355ebdd9700e318b3f1078e9799f948cf1195
parent6bf7c9fd297e494f9173dda9d5518836e41dfb01 (diff)
parentbd273be1f2c15daaa71420cc333607dc06c4bdae (diff)
downloadcmd2-git-a9f7c775dda166ae9f376d0eecd3cb9576ccef16.tar.gz
Merge pull request #130 from python-cmd2/command_space
Added override of cmd.completenames() method
-rwxr-xr-xcmd2.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmd2.py b/cmd2.py
index 46eb4926..9129757a 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -765,6 +765,18 @@ class Cmd(cmd.Cmd):
# ----- Methods which override stuff in cmd -----
+ # noinspection PyMethodOverriding
+ def completenames(self, text, line, begidx, endidx):
+ """Override of cmd2 method which completes command names both for command completion and help."""
+ # Call super class method. Need to do it this way for Python 2 and 3 compatibility
+ cmd_completion = cmd.Cmd.completenames(self, text)
+
+ # If we are completing the initial command name and get exactly 1 result, add a space afterwards for convenience
+ if begidx == 0 and len(cmd_completion) == 1:
+ cmd_completion[0] += ' '
+
+ return cmd_completion
+
def precmd(self, statement):
"""Hook method executed just before the command is processed by ``onecmd()`` and after adding it to the history.
@@ -1543,7 +1555,7 @@ class Cmd(cmd.Cmd):
"""Run a cmd2.Cmd command from a Python script or the interactive Python console.
:param cmd_plus_args: str - command line including command and arguments to run
- :return: bool - True if cmdloop() should exit once leaving the interactive Python console, False otherwise.
+ :return: bool - True if cmdloop() should exit once leaving the interactive Python console
"""
return self.onecmd_plus_hooks(cmd_plus_args + '\n')
@@ -1559,7 +1571,7 @@ class Cmd(cmd.Cmd):
else:
# noinspection PyShadowingBuiltins
def quit():
- """Function callable from the interactive Python console to exit that environment and return to cmd2."""
+ """Function callable from the interactive Python console to exit that environment"""
raise EmbeddedConsoleExit
self.pystate['quit'] = quit
@@ -1572,7 +1584,8 @@ class Cmd(cmd.Cmd):
sys.stdout = self.stdout
sys.stdin = self.stdin
interp.interact(banner="Python %s on %s\n%s\n(%s)\n%s" %
- (sys.version, sys.platform, cprt, self.__class__.__name__, self.do_py.__doc__))
+ (sys.version, sys.platform, cprt, self.__class__.__name__,
+ self.do_py.__doc__))
except EmbeddedConsoleExit:
pass
if keepstate is not None: