Commits

Georg Brandl committed 8e82dd5

#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.

Comments (0)

Files changed (2)

             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:

Lib/test/test_cmd.py

     >>> mycmd.completenames("12")
     []
     >>> mycmd.completenames("help")
-    ['help', 'help']
+    ['help']
 
     Test for the function complete_help():
     >>> mycmd.complete_help("a")
     ['add']
     >>> mycmd.complete_help("he")
-    ['help', 'help']
+    ['help']
     >>> mycmd.complete_help("12")
     []
+    >>> sorted(mycmd.complete_help(""))
+    ['add', 'exit', 'help', 'shell']
 
     Test for the function do_help():
     >>> mycmd.do_help("testet")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.