#5991: let completion for the "help" command include help topics.

This also simplifies the Cmd.get_names() method implementation; it was written
at a time where dir() didn't consider base class attributes.
This commit is contained in:
Georg Brandl 2010-01-06 18:02:16 +00:00
parent 5089a38af2
commit 8904053003
2 changed files with 11 additions and 13 deletions

View file

@ -281,19 +281,15 @@ class Cmd:
return None
def get_names(self):
# Inheritance says we have to look in class and
# base classes; order is not important.
names = []
classes = [self.__class__]
while classes:
aclass = classes.pop(0)
if aclass.__bases__:
classes = classes + list(aclass.__bases__)
names = names + dir(aclass)
return names
# This method used to pull in base class attributes
# at a time dir() didn't do it yet.
return dir(self.__class__)
def complete_help(self, *args):
return self.completenames(*args)
commands = set(self.completenames(*args))
topics = set(a[5:] for a in self.get_names()
if a.startswith('help_' + args[0]))
return list(commands | topics)
def do_help(self, arg):
if arg: