Patchwork [2,of,2] help: suggest keyword search when no topic is found

login
register
mail settings
Submitter Pierre-Yves David
Date May 8, 2014, 1:34 a.m.
Message ID <8da30f1d94ece24d09e1.1399512843@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4662/
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 1397692540 14400
#      Wed Apr 16 19:55:40 2014 -0400
# Node ID 8da30f1d94ece24d09e1bd37048e6c8fdca48b7e
# Parent  a710227126175922ece1d5604edfdf948f348290
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.
Augie Fackler - May 13, 2014, 1:05 a.m.
On Wed, May 07, 2014 at 06:34:03PM -0700, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1397692540 14400
> #      Wed Apr 16 19:55:40 2014 -0400
> # Node ID 8da30f1d94ece24d09e1bd37048e6c8fdca48b7e
> # Parent  a710227126175922ece1d5604edfdf948f348290
> help: suggest keyword search when no topic is found

These look reasonable. Queued.

>
> 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.
>
> diff --git a/mercurial/help.py b/mercurial/help.py
> --- a/mercurial/help.py
> +++ b/mercurial/help.py
> @@ -484,11 +484,10 @@ def help_(ui, name, unknowncmd=False, fu
>          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'):
>              queries = (helpext,)
>          elif opts.get('command'):
> @@ -496,16 +495,20 @@ def help_(ui, name, unknowncmd=False, fu
>          else:
>              queries = (helptopic, helpcmd, helpext, helpextcmd)
>          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:
>              rst = [_("Mercurial Distributed SCM\n"), '\n']
>          rst.extend(helplist())
> diff --git a/tests/test-extension.t b/tests/test-extension.t
> --- a/tests/test-extension.t
> +++ b/tests/test-extension.t
> @@ -619,12 +619,12 @@ Broken disabled extension and command:
>    $ cat > hgext/forest.py <<EOF
>    > cmdtable = None
>    > 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
>    > from mercurial import cmdutil, commands
>    > cmdtable = {}
> diff --git a/tests/test-help.t b/tests/test-help.t
> --- a/tests/test-help.t
> +++ b/tests/test-help.t
> @@ -594,34 +594,12 @@ Test command without options
>    hg status [OPTION]... [FILE]...
>
>    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
>    hg: unknown command 'skjdfks'
>    Mercurial Distributed SCM
> @@ -986,10 +964,17 @@ Test keyword search help
>
>    Extension Commands:
>
>     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
>    abort: no matches
>    (try "hg help" for a list of topics)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -484,11 +484,10 @@  def help_(ui, name, unknowncmd=False, fu
         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'):
             queries = (helpext,)
         elif opts.get('command'):
@@ -496,16 +495,20 @@  def help_(ui, name, unknowncmd=False, fu
         else:
             queries = (helptopic, helpcmd, helpext, helpextcmd)
         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:
             rst = [_("Mercurial Distributed SCM\n"), '\n']
         rst.extend(helplist())
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -619,12 +619,12 @@  Broken disabled extension and command:
   $ cat > hgext/forest.py <<EOF
   > cmdtable = None
   > 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
   > from mercurial import cmdutil, commands
   > cmdtable = {}
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -594,34 +594,12 @@  Test command without options
   hg status [OPTION]... [FILE]...
   
   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
   hg: unknown command 'skjdfks'
   Mercurial Distributed SCM
@@ -986,10 +964,17 @@  Test keyword search help
   
   Extension Commands:
   
    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
   abort: no matches
   (try "hg help" for a list of topics)