changeset 31080:ab20491b1760

dispatch: rearrange 'unknown command' code to better employ pager dispatch calls help like a ninja if you give it a truly unknown command, and that might want to be paged. If it gets paged, then the 'hg: unknown command' text gets eaten by a grue, unless we call the pager first. This change rearranges the codepaths so we can safely only invoke the pager in the case where we'll have long output from the help command code, rather than just a short message like "did you mean stat instead of start" or "fetch is provided by the fetch extension".
author Augie Fackler <augie@google.com>
date Tue, 21 Feb 2017 14:20:05 -0500
parents 2a0c8e3636b0
children 900996da577a
files mercurial/dispatch.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Tue Feb 21 14:17:31 2017 -0500
+++ b/mercurial/dispatch.py	Tue Feb 21 14:20:05 2017 -0500
@@ -33,6 +33,7 @@
     extensions,
     fancyopts,
     fileset,
+    help,
     hg,
     hook,
     profiling,
@@ -242,19 +243,24 @@
         _formatparse(ui.warn, inst)
         return -1
     except error.UnknownCommand as inst:
-        ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
+        nocmdmsg = _("hg: unknown command '%s'\n") % inst.args[0]
         try:
             # check if the command is in a disabled extension
             # (but don't check for extensions themselves)
-            commands.help_(ui, inst.args[0], unknowncmd=True)
+            formatted = help.formattedhelp(ui, inst.args[0], unknowncmd=True)
+            ui.warn(nocmdmsg)
+            ui.write(formatted)
         except (error.UnknownCommand, error.Abort):
             suggested = False
             if len(inst.args) == 2:
                 sim = _getsimilar(inst.args[1], inst.args[0])
                 if sim:
+                    ui.warn(nocmdmsg)
                     _reportsimilar(ui.warn, sim)
                     suggested = True
             if not suggested:
+                ui.pager('help')
+                ui.warn(nocmdmsg)
                 commands.help_(ui, 'shortlist')
     except IOError:
         raise