summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-24 18:15:27 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-24 18:15:27 -0400
commitefd3b2cbe243dc520dab4146fae014c19447af53 (patch)
tree104b14c63e8ac352b30e62232bd83bf45b219f92 /cmd2.py
parent40f8a84dc0177097c8c0f97e91a8b514d1540c0f (diff)
downloadcmd2-git-efd3b2cbe243dc520dab4146fae014c19447af53.tar.gz
Made subcommand specific completion work with Python 2 in the examples
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index 439c6e38..3249d398 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1911,14 +1911,14 @@ class Cmd(cmd.Cmd):
except AttributeError:
compfunc = self.completedefault
- # If there are subcommands, then try completing those if the cursor is in
- # the token at index 1, otherwise default to using compfunc
subcommands = self.get_subcommands(command)
if subcommands is not None:
+ # Since there are subcommands, then try completing those if the cursor is in
+ # the token at index 1, otherwise default to using compfunc
index_dict = {1: subcommands}
- compfunc = functools.partialmethod(self.index_based_complete,
- index_dict=index_dict,
- all_else=compfunc)
+ compfunc = functools.partial(self.index_based_complete,
+ index_dict=index_dict,
+ all_else=compfunc)
# A valid command was not entered
else:
@@ -2904,10 +2904,11 @@ Usage: Usage: unalias [-a] name [name ...]
To make sure these functions get called, set the tab-completer for the print function
in a similar fashion to what follows where base is the name of the root command (print)
- complete_print = functools.partialmethod(cmd2.Cmd.cmd_with_subs_completer, base='print')
+ def complete_print(self, text, line, begidx, endidx):
+ return self.cmd_with_subs_completer(text, line, begidx, endidx, base='print')
When the subcommand's completer is called, this function will have stripped off all content from the
- beginning of he command line before the subcommand, meaning the line parameter always starts with the
+ beginning of the command line before the subcommand, meaning the line parameter always starts with the
subcommand name and the index parameters reflect this change.
For instance, the command "print names -d 2" becomes "names -d 2"