changeset 27623:b3376fba4ab9

dispatch: report similar names consistently
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 04 Jan 2016 21:52:44 -0800
parents 0bc71f45d362
children d46db4390715
files mercurial/dispatch.py tests/test-alias.t tests/test-help.t tests/test-revset.t
diffstat 4 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Mon Jan 04 16:14:04 2016 -0800
+++ b/mercurial/dispatch.py	Mon Jan 04 21:52:44 2016 -0800
@@ -59,6 +59,13 @@
     # probably be investigated and tweaked.
     return [s for s in symbols if sim(s) > 0.6]
 
+def _reportsimilar(write, similar):
+    if len(similar) == 1:
+        write(_("(did you mean %s?)\n") % similar[0])
+    elif similar:
+        ss = ", ".join(sorted(similar))
+        write(_("(did you mean one of %s?)\n") % ss)
+
 def _formatparse(write, inst):
     similar = []
     if isinstance(inst, error.UnknownIdentifier):
@@ -71,12 +78,7 @@
             write(_("unexpected leading whitespace\n"))
     else:
         write(_("hg: parse error: %s\n") % inst.args[0])
-        if similar:
-            if len(similar) == 1:
-                write(_("(did you mean %r?)\n") % similar[0])
-            else:
-                ss = ", ".join(sorted(similar))
-                write(_("(did you mean one of %s?)\n") % ss)
+        _reportsimilar(write, similar)
 
 def dispatch(req):
     "run the command specified in req.args"
@@ -262,8 +264,7 @@
             if len(inst.args) == 2:
                 sim = _getsimilar(inst.args[1], inst.args[0])
                 if sim:
-                    ui.warn(_('(did you mean one of %s?)\n') %
-                            ', '.join(sorted(sim)))
+                    _reportsimilar(ui.warn, sim)
                     suggested = True
             if not suggested:
                 commands.help_(ui, 'shortlist')
--- a/tests/test-alias.t	Mon Jan 04 16:14:04 2016 -0800
+++ b/tests/test-alias.t	Mon Jan 04 21:52:44 2016 -0800
@@ -360,11 +360,11 @@
   sub
   $ hg --cwd .. subalias > /dev/null
   hg: unknown command 'subalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
   $ hg -R .. subalias > /dev/null
   hg: unknown command 'subalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
 
 
@@ -372,7 +372,7 @@
 
   $ hg mainalias > /dev/null
   hg: unknown command 'mainalias'
-  (did you mean one of idalias?)
+  (did you mean idalias?)
   [255]
   $ hg -R .. mainalias
   main
--- a/tests/test-help.t	Mon Jan 04 16:14:04 2016 -0800
+++ b/tests/test-help.t	Mon Jan 04 21:52:44 2016 -0800
@@ -645,12 +645,12 @@
 
   $ hg .log
   hg: unknown command '.log'
-  (did you mean one of log?)
+  (did you mean log?)
   [255]
 
   $ hg log.
   hg: unknown command 'log.'
-  (did you mean one of log?)
+  (did you mean log?)
   [255]
   $ hg pu.lh
   hg: unknown command 'pu.lh'
--- a/tests/test-revset.t	Mon Jan 04 16:14:04 2016 -0800
+++ b/tests/test-revset.t	Mon Jan 04 21:52:44 2016 -0800
@@ -1482,11 +1482,11 @@
 Bogus function gets suggestions
   $ log 'add()'
   hg: parse error: unknown identifier: add
-  (did you mean 'adds'?)
+  (did you mean adds?)
   [255]
   $ log 'added()'
   hg: parse error: unknown identifier: added
-  (did you mean 'adds'?)
+  (did you mean adds?)
   [255]
   $ log 'remo()'
   hg: parse error: unknown identifier: remo
@@ -1499,7 +1499,7 @@
 Bogus function with a similar internal name doesn't suggest the internal name
   $ log 'matches()'
   hg: parse error: unknown identifier: matches
-  (did you mean 'matching'?)
+  (did you mean matching?)
   [255]
 
 Undocumented functions aren't suggested as similar either