help: suggest keyword search when no topic is found
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 16 Apr 2014 19:55:40 -0400
changeset 21289 c3784e3c3e8d
parent 21288 eb6eaef7ae44
child 21290 74be3fb1e3b8
help: suggest keyword search when no topic is found When `hg help foobar` fails, it now suggests using `hg help --keyword foobar` instead of printing a full page of basic commands. This should greatly increases discoverability of the `hg help --keyword` argument.
mercurial/help.py
tests/test-extension.t
tests/test-help.t
--- a/mercurial/help.py	Wed Apr 16 20:01:03 2014 -0400
+++ b/mercurial/help.py	Wed Apr 16 19:55:40 2014 -0400
@@ -486,7 +486,6 @@
             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'):
@@ -498,12 +497,16 @@
         for f in queries:
             try:
                 rst = f(name)
-                i = None
                 break
-            except error.UnknownCommand, inst:
-                i = inst
-        if i:
-            raise i
+            except error.UnknownCommand:
+                pass
+        else:
+            if unknowncmd:
+                raise error.UnknownCommand(name)
+            else:
+                msg = _('no such help topic: %s') % name
+                hint = _('try "hg help --keyword %s"') % name
+                raise util.Abort(msg, hint=hint)
     else:
         # program name
         if not ui.quiet:
--- a/tests/test-extension.t	Wed Apr 16 20:01:03 2014 -0400
+++ b/tests/test-extension.t	Wed Apr 16 19:55:40 2014 -0400
@@ -621,8 +621,8 @@
   > EOF
   $ hg --config extensions.path=./path.py help foo > /dev/null
   warning: error finding commands in $TESTTMP/hgext/forest.py (glob)
-  hg: unknown command 'foo'
-  warning: error finding commands in $TESTTMP/hgext/forest.py (glob)
+  abort: no such help topic: foo
+  (try "hg help --keyword foo")
   [255]
 
   $ cat > throw.py <<EOF
--- a/tests/test-help.t	Wed Apr 16 20:01:03 2014 -0400
+++ b/tests/test-help.t	Wed Apr 16 19:55:40 2014 -0400
@@ -596,30 +596,8 @@
   show changed files in the working directory
 
   $ hg help foo
-  hg: unknown command 'foo'
-  Mercurial Distributed SCM
-  
-  basic commands:
-  
-   add           add the specified files on the next commit
-   annotate      show changeset information by line for each file
-   clone         make a copy of an existing repository
-   commit        commit the specified files or all outstanding changes
-   diff          diff repository (or selected files)
-   export        dump the header and diffs for one or more changesets
-   forget        forget the specified files on the next commit
-   init          create a new repository in the given directory
-   log           show revision history of entire repository or files
-   merge         merge working directory with another revision
-   pull          pull changes from the specified source
-   push          push changes to the specified destination
-   remove        remove the specified files on the next commit
-   serve         start stand-alone webserver
-   status        show changed files in the working directory
-   summary       summarize working directory state
-   update        update working directory (or switch revisions)
-  
-  use "hg help" for the full list of commands or "hg -v" for details
+  abort: no such help topic: foo
+  (try "hg help --keyword foo")
   [255]
 
   $ hg skjdfks
@@ -988,6 +966,13 @@
   
    qclone clone main and patch repository at same time
 
+Test unfound topic
+
+  $ hg help nonexistingtopicthatwillneverexisteverever
+  abort: no such help topic: nonexistingtopicthatwillneverexisteverever
+  (try "hg help --keyword nonexistingtopicthatwillneverexisteverever")
+  [255]
+
 Test unfound keyword
 
   $ hg help --keyword nonexistingwordthatwillneverexisteverever