diff mercurial/commands.py @ 4932:93b7e2fa7ee3

help: avoid traceback if an extension has only debug commands
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 19 Jul 2007 19:43:25 -0300
parents b8076522e889
children 90be978c9d3d 8d982aef0be1
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1340,7 +1340,7 @@ def help_(ui, name=None, with_version=Fa
 
             addglobalopts(False)
 
-    def helplist(select=None):
+    def helplist(header, select=None):
         h = {}
         cmds = {}
         for c, e in table.items():
@@ -1358,6 +1358,11 @@ def help_(ui, name=None, with_version=Fa
             h[f] = doc.splitlines(0)[0].rstrip()
             cmds[f] = c.lstrip("^")
 
+        if not h:
+            ui.status(_('no commands defined\n'))
+            return
+
+        ui.status(header)
         fns = h.keys()
         fns.sort()
         m = max(map(len, fns))
@@ -1407,14 +1412,10 @@ def help_(ui, name=None, with_version=Fa
         try:
             ct = mod.cmdtable
         except AttributeError:
-            ct = None
-        if not ct:
-            ui.status(_('no commands defined\n'))
-            return
-
-        ui.status(_('list of commands:\n\n'))
+            ct = {}
+
         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
-        helplist(modcmds.has_key)
+        helplist(_('list of commands:\n\n'), modcmds.has_key)
 
     if name and name != 'shortlist':
         i = None
@@ -1438,11 +1439,11 @@ def help_(ui, name=None, with_version=Fa
 
         # list of commands
         if name == "shortlist":
-            ui.status(_('basic commands:\n\n'))
+            header = _('basic commands:\n\n')
         else:
-            ui.status(_('list of commands:\n\n'))
-
-        helplist()
+            header = _('list of commands:\n\n')
+
+        helplist(header)
 
     # list all option lists
     opt_output = []