Patchwork D9166: errors: name arguments to UnknownCommand constructor

login
register
mail settings
Submitter phabricator
Date Oct. 7, 2020, 6:10 a.m.
Message ID <differential-rev-PHID-DREV-5gs37kv7zl55uyuvjzjs-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47394/
State Superseded
Headers show

Comments

phabricator - Oct. 7, 2020, 6:10 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dispatch.py
  mercurial/error.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -111,6 +111,11 @@ 
 class UnknownCommand(Exception):
     """Exception raised if command is not in the command table."""
 
+    def __init__(self, command, all_commands=None):
+        self.command = command
+        self.all_commands = all_commands
+        super(UnknownCommand, self).__init__()
+
     __bytes__ = _tobytes
 
 
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -504,19 +504,19 @@ 
         _formatparse(ui.warn, inst)
         return -1
     except error.UnknownCommand as inst:
-        nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.args[0]
+        nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command
         try:
             # check if the command is in a disabled extension
             # (but don't check for extensions themselves)
             formatted = help.formattedhelp(
-                ui, commands, inst.args[0], unknowncmd=True
+                ui, commands, inst.command, 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 inst.all_commands:
+                sim = _getsimilar(inst.all_commands, inst.command)
                 if sim:
                     ui.warn(nocmdmsg)
                     _reportsimilar(ui.warn, sim)