Patchwork [1,of,2] help: provide a more helpful message when no keyword are matched

login
register
mail settings
Submitter Pierre-Yves David
Date May 8, 2014, 1:34 a.m.
Message ID <a710227126175922ece1.1399512842@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4661/
State Accepted
Headers show

Comments

Pierre-Yves David - May 8, 2014, 1:34 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1397692863 14400
#      Wed Apr 16 20:01:03 2014 -0400
# Node ID a710227126175922ece1d5604edfdf948f348290
# Parent  62a2749895e4151f766a4243fa870b1ddd7386d0
help: provide a more helpful message when no keyword are matched

Before this changeset, when no topic were matching the provided keyword ( in
command such as `hg help --keyword babar`) the output was empty. This is
confusing and unhelpful for new users seeking assistance in the help.

We now display:

  $ hg help --keyword babar
  abort: no matches
  (try "hg help" for a list of topics)

This send users in a new direction where they may find what they are looking for.

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -479,10 +479,14 @@  def help_(ui, name, unknowncmd=False, fu
                          ('extensioncommands', _('Extension Commands'))):
             if matches[t]:
                 rst.append('%s:\n\n' % title)
                 rst.extend(minirst.maketable(sorted(matches[t]), 1))
                 rst.append('\n')
+        if not rst:
+            msg = _('no matches')
+            hint = _('try "hg help" for a list of topics')
+            raise util.Abort(msg, hint=hint)
     elif name and name != 'shortlist':
         i = None
         if unknowncmd:
             queries = (helpextcmd,)
         elif opts.get('extension'):
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -986,10 +986,17 @@  Test keyword search help
   
   Extension Commands:
   
    qclone clone main and patch repository at same time
 
+Test unfound keyword
+
+  $ hg help --keyword nonexistingwordthatwillneverexisteverever
+  abort: no matches
+  (try "hg help" for a list of topics)
+  [255]
+
 Test omit indicating for help
 
   $ cat > addverboseitems.py <<EOF
   > '''extension to test omit indicating.
   >