@@ -765,6 +765,18 @@ def colorize(self, val, color):
765765
766766 # ----- Methods which override stuff in cmd -----
767767
768+ # noinspection PyMethodOverriding
769+ def completenames (self , text , line , begidx , endidx ):
770+ """Override of cmd2 method which completes command names both for command completion and help."""
771+ # Call super class method. Need to do it this way for Python 2 and 3 compatibility
772+ cmd_completion = cmd .Cmd .completenames (self , text )
773+
774+ # If we are completing the initial command name and get exactly 1 result, add a space afterwards for convenience
775+ if begidx == 0 and len (cmd_completion ) == 1 :
776+ cmd_completion [0 ] += ' '
777+
778+ return cmd_completion
779+
768780 def precmd (self , statement ):
769781 """Hook method executed just before the command is processed by ``onecmd()`` and after adding it to the history.
770782
@@ -1543,7 +1555,7 @@ def onecmd_plus_hooks(cmd_plus_args):
15431555 """Run a cmd2.Cmd command from a Python script or the interactive Python console.
15441556
15451557 :param cmd_plus_args: str - command line including command and arguments to run
1546- :return: bool - True if cmdloop() should exit once leaving the interactive Python console, False otherwise.
1558+ :return: bool - True if cmdloop() should exit once leaving the interactive Python console
15471559 """
15481560 return self .onecmd_plus_hooks (cmd_plus_args + '\n ' )
15491561
@@ -1559,7 +1571,7 @@ def onecmd_plus_hooks(cmd_plus_args):
15591571 else :
15601572 # noinspection PyShadowingBuiltins
15611573 def quit ():
1562- """Function callable from the interactive Python console to exit that environment and return to cmd2. """
1574+ """Function callable from the interactive Python console to exit that environment"""
15631575 raise EmbeddedConsoleExit
15641576
15651577 self .pystate ['quit' ] = quit
@@ -1572,7 +1584,8 @@ def quit():
15721584 sys .stdout = self .stdout
15731585 sys .stdin = self .stdin
15741586 interp .interact (banner = "Python %s on %s\n %s\n (%s)\n %s" %
1575- (sys .version , sys .platform , cprt , self .__class__ .__name__ , self .do_py .__doc__ ))
1587+ (sys .version , sys .platform , cprt , self .__class__ .__name__ ,
1588+ self .do_py .__doc__ ))
15761589 except EmbeddedConsoleExit :
15771590 pass
15781591 if keepstate is not None :
0 commit comments