Patchwork D6442: help: include subtopic in error message if passed

login
register
mail settings
Submitter phabricator
Date May 23, 2019, 3:36 p.m.
Message ID <differential-rev-PHID-DREV-4sdzyi2b7uwxf2nvsl3b-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40211/
State Superseded
Headers show

Comments

phabricator - May 23, 2019, 3:36 p.m.
ngoldbaum created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6442

AFFECTED FILES
  mercurial/help.py
  tests/test-help.t

CHANGE DETAILS




To: ngoldbaum, #hg-reviewers
Cc: mercurial-devel
phabricator - May 24, 2019, 1:06 p.m.
av6 added inline comments.

INLINE COMMENTS

> help.py:826
> +                if subtopic:
> +                    hint += _(" or 'hg help --keyword %s'") % subtopic
>                  raise error.Abort(msg, hint=hint)

Concatenating things is not the best option when it comes to i18n, but even if it were, I think it would make sense to only show here the subtopic, if it's provided. If people are curious about internals.foobar (or config.foobar), then `hg help -k foobar` helps way more than `hg help -k internals`. And we already make sure that the topic that comes before the dot exists, right?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6442

To: ngoldbaum, #hg-reviewers
Cc: av6, mercurial-devel
phabricator - May 24, 2019, 1:20 p.m.
ngoldbaum added inline comments.

INLINE COMMENTS

> av6 wrote in help.py:826
> Concatenating things is not the best option when it comes to i18n, but even if it were, I think it would make sense to only show here the subtopic, if it's provided. If people are curious about internals.foobar (or config.foobar), then `hg help -k foobar` helps way more than `hg help -k internals`. And we already make sure that the topic that comes before the dot exists, right?

Fair enough, I agree just the subtopic is fine.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6442

To: ngoldbaum, #hg-reviewers
Cc: av6, mercurial-devel

Patch

diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1303,6 +1303,13 @@ 
       *empty chunk* at the end of each *delta group* denotes the boundary to the
       next filelog sub-segment.
 
+non-existent subtopics print an error
+
+  $ hg help internals.foo
+  abort: no such help topic: internals.foo
+  (try 'hg help --keyword internals' or 'hg help --keyword foo')
+  [255]
+
 test advanced, deprecated and experimental options are hidden in command help
   $ hg help debugoptADV
   hg debugoptADV
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -453,7 +453,7 @@ 
 addtopichook('config', inserttweakrc)
 
 def help_(ui, commands, name, unknowncmd=False, full=True, subtopic=None,
-          **opts):
+          fullname=None, **opts):
     '''
     Generate the help for 'name' as unformatted restructured text. If
     'name' is None, describe the commands available.
@@ -816,8 +816,14 @@ 
             if unknowncmd:
                 raise error.UnknownCommand(name)
             else:
-                msg = _('no such help topic: %s') % name
+                if fullname:
+                    formatname = fullname
+                else:
+                    formatname = name
+                msg = _('no such help topic: %s') % formatname
                 hint = _("try 'hg help --keyword %s'") % name
+                if subtopic:
+                    hint += _(" or 'hg help --keyword %s'") % subtopic
                 raise error.Abort(msg, hint=hint)
     else:
         # program name
@@ -852,7 +858,7 @@ 
     termwidth = ui.termwidth() - 2
     if textwidth <= 0 or termwidth < textwidth:
         textwidth = termwidth
-    text = help_(ui, commands, name,
+    text = help_(ui, commands, name, fullname=fullname,
                  subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts)
 
     blocks, pruned = minirst.parse(text, keep=keep)