[PATCH 1 of 4] commands: makes help_.helplist throw error.UnknownCommand if nothing found

Henri Wiechers hwiechers at gmail.com
Tue Jan 12 08:55:21 UTC 2010


# HG changeset patch
# User Henri Wiechers <hwiechers at gmail.com>
# Date 1263280428 -7200
# Node ID 76445c51851b2fb4f10a43216829a3b28cef5ad5
# Parent  c8d6f339bbd7c2fecfb0f57464b2dbb8fc0db47e
commands: makes help_.helplist throw error.UnknownCommand if nothing found

Functions calling help_.helplist can now tell if no commands were found and
take action as needed.

diff -r c8d6f339bbd7 -r 76445c51851b mercurial/commands.py
--- a/mercurial/commands.py	Mon Jan 11 21:15:53 2010 +0100
+++ b/mercurial/commands.py	Tue Jan 12 09:13:48 2010 +0200
@@ -1485,7 +1485,10 @@
             # except block, nor can be used inside a lambda. python issue4617
             prefix = inst.args[0]
             select = lambda c: c.lstrip('^').startswith(prefix)
-            helplist(_('list of commands:\n\n'), select)
+            try:
+                helplist(_('list of commands:\n\n'), select)
+            except error.UnknownCommand:
+                ui.status(_('no commands defined\n'))
             return
 
         # check if it's an invalid alias and display its error if it is
@@ -1546,8 +1549,7 @@
             cmds[f] = c.lstrip("^")
 
         if not h:
-            ui.status(_('no commands defined\n'))
-            return
+            raise error.UnknownCommand(name)
 
         ui.status(header)
         fns = sorted(h)
@@ -1600,7 +1602,11 @@
             ct = {}
 
         modcmds = set([c.split('|', 1)[0] for c in ct])
-        helplist(_('list of commands:\n\n'), modcmds.__contains__)
+        try:
+            helplist(_('list of commands:\n\n'), modcmds.__contains__)
+        except error.UnknownCommand:
+            ui.status(_('no commands defined\n'))
+            return
 
     if name and name != 'shortlist':
         i = None
@@ -1628,7 +1634,11 @@
         else:
             header = _('list of commands:\n\n')
 
-        helplist(header)
+        try:
+            helplist(header)
+        except error.UnknownCommand:
+            ui.status(_('no commands defined\n'))
+
         if name != 'shortlist':
             exts, maxlength = extensions.enabled()
             text = help.listexts(_('enabled extensions:'), exts, maxlength)



More information about the Mercurial-devel mailing list