changeset 10021:0022f5c5459e

help: don't display bogus help messages for invalid aliases
author Brodie Rao <me+hg@dackz.net>
date Sat, 05 Dec 2009 23:26:27 -0500
parents d7c23f4a14c7
children 15fbbc939373
files mercurial/commands.py mercurial/dispatch.py tests/test-alias tests/test-alias.out
diffstat 4 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Dec 05 23:16:09 2009 +0100
+++ b/mercurial/commands.py	Sat Dec 05 23:26:27 2009 -0500
@@ -1486,6 +1486,11 @@
             helplist(_('list of commands:\n\n'), select)
             return
 
+        # check if it's an invalid alias and display its error if it is
+        if getattr(entry[0], 'badalias', False):
+            entry[0](ui)
+            return
+
         # synopsis
         if len(entry) > 2:
             if entry[2].startswith('hg'):
--- a/mercurial/dispatch.py	Sat Dec 05 23:16:09 2009 +0100
+++ b/mercurial/dispatch.py	Sat Dec 05 23:26:27 2009 -0500
@@ -177,6 +177,7 @@
         self.opts = []
         self.help = ''
         self.norepo = True
+        self.badalias = False
 
         try:
             cmdutil.findcmd(self.name, cmdtable, True)
@@ -189,6 +190,7 @@
                 ui.warn(_("no definition for alias '%s'\n") % self.name)
                 return 1
             self.fn = fn
+            self.badalias = True
 
             return
 
@@ -217,12 +219,14 @@
                             % (self.name, cmd))
                 return 1
             self.fn = fn
+            self.badalias = True
         except error.AmbiguousCommand:
             def fn(ui, *args):
                 ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \
                             % (self.name, cmd))
                 return 1
             self.fn = fn
+            self.badalias = True
 
     def __call__(self, ui, *args, **opts):
         if self.shadows:
--- a/tests/test-alias	Sat Dec 05 23:16:09 2009 +0100
+++ b/tests/test-alias	Sat Dec 05 23:26:27 2009 -0500
@@ -25,15 +25,19 @@
 
 echo '% unknown'
 hg unknown
+hg help unknown
 
 echo '% ambiguous'
 hg ambiguous
+hg help ambiguous
 
 echo '% recursive'
 hg recursive
+hg help recursive
 
 echo '% no definition'
 hg nodef
+hg help nodef
 
 cd alias
 
--- a/tests/test-alias.out	Sat Dec 05 23:16:09 2009 +0100
+++ b/tests/test-alias.out	Sat Dec 05 23:26:27 2009 -0500
@@ -1,12 +1,16 @@
 % basic
 % unknown
 alias 'unknown' resolves to unknown command 'bargle'
+alias 'unknown' resolves to unknown command 'bargle'
 % ambiguous
 alias 'ambiguous' resolves to ambiguous command 's'
+alias 'ambiguous' resolves to ambiguous command 's'
 % recursive
 alias 'recursive' resolves to unknown command 'recursive'
+alias 'recursive' resolves to unknown command 'recursive'
 % no definition
 no definition for alias 'nodefinition'
+no definition for alias 'nodefinition'
 % no usage
 no rollback information available
 adding foo