Patchwork [1,of,2] dispatch: distinguish single and multiple similar suggested commands in hint

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Sept. 25, 2015, 4:24 p.m.
Message ID <c14d27fbb5a6568a2328.1443198251@Iris>
Download mbox | patch
Permalink /patch/10635/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - Sept. 25, 2015, 4:24 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1443195363 14400
#      Fri Sep 25 11:36:03 2015 -0400
# Node ID c14d27fbb5a6568a232843887a63660e90208cbe
# Parent  b80b2ee71a08d00ec4008f3131bdf3c72e4ec2ba
dispatch: distinguish single and multiple similar suggested commands in hint

Before this, a command like `hg pushs` would say "did you mean one of
push?", which is wrong, since there is only one suggestion.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -258,8 +258,11 @@  def _runcatch(req):
             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)))
+                    if len(sim) == 1:
+                        ui.warn(_("(did you mean '%s'?)\n") % sim[0])
+                    else:
+                        ui.warn(_("(did you mean one of %s?)\n") %
+                                ', '.join("'%s'" % s for s in sorted(sim)))
                     suggested = True
             if not suggested:
                 commands.help_(ui, 'shortlist')
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -360,11 +360,11 @@  shell alias defined in current repo
   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 @@  shell alias defined in other repo
 
   $ hg mainalias > /dev/null
   hg: unknown command 'mainalias'
-  (did you mean one of idalias?)
+  (did you mean 'idalias'?)
   [255]
   $ hg -R .. mainalias
   main
@@ -382,7 +382,7 @@  shell alias defined in other repo
 typos get useful suggestions
   $ hg --cwd .. manalias
   hg: unknown command 'manalias'
-  (did you mean one of idalias, mainalias, manifest?)
+  (did you mean one of 'idalias', 'mainalias', 'manifest'?)
   [255]
 
 shell aliases with escaped $ chars
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -615,6 +615,16 @@  Test command without options
   (use "hg help" for the full list of commands or "hg -v" for details)
   [255]
 
+Test command suggestion, both one or multiple
+
+  $ hg pulh
+  hg: unknown command 'pulh'
+  (did you mean one of 'pull', 'push'?)
+  [255]
+  $ hg lol
+  hg: unknown command 'lol'
+  (did you mean 'log'?)
+  [255]
 
   $ cat > helpext.py <<EOF
   > import os