[PATCH 3 of 7 evolve-ext] exthelper: support the option argument when registering a command

Matt Harbison mharbison72 at gmail.com
Thu Jan 3 00:30:50 EST 2019


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1545620096 18000
#      Sun Dec 23 21:54:56 2018 -0500
# Node ID f1f44dddfd78833595529ebce0c347ad467b6673
# Parent  708bf337a93e8e136fdf25aabf927ee44f3460ad
exthelper: support the option argument when registering a command

Largefiles uses this 5th argument with push and pull, so this will be tested in
the next commit.  I assume the reason for unrolling and reforming the tuple in
each finalxxxsetup() is to validate that something proper was passed in when
registering.  But it's better to explode when decorating than during the delayed
actual registration.

diff --git a/hgext3rd/evolve/exthelper.py b/hgext3rd/evolve/exthelper.py
--- a/hgext3rd/evolve/exthelper.py
+++ b/hgext3rd/evolve/exthelper.py
@@ -11,6 +11,7 @@
 
 from mercurial import (
     commands,
+    error,
     extensions,
     fileset as filesetmod,
     registrar,
@@ -96,8 +97,8 @@
         for command, wrapper, opts in self._commandwrappers:
             entry = extensions.wrapcommand(commands.table, command, wrapper)
             if opts:
-                for short, long, val, msg in opts:
-                    entry[1].append((short, long, val, msg))
+                for opt in opts:
+                    entry[1].append(opt)
         for cont, funcname, wrapper in self._functionwrappers:
             extensions.wrapfunction(cont, funcname, wrapper)
         for c in self._uicallables:
@@ -157,8 +158,8 @@
                 knownexts[ext] = e.cmdtable
             entry = extensions.wrapcommand(knownexts[ext], command, wrapper)
             if opts:
-                for short, long, val, msg in opts:
-                    entry[1].append((short, long, val, msg))
+                for opt in opts:
+                    entry[1].append(opt)
 
         for c in self._extcallables:
             c(ui)
@@ -294,12 +295,21 @@
                 ui.note('Barry!')
                 return orig(ui, repo, *args, **kwargs)
 
-        The `opts` argument allows specifying additional arguments for the
-        command.
+        The `opts` argument allows specifying a list of tuples for additional
+        arguments for the command.  See ``mercurial.fancyopts.fancyopts()`` for
+        the format of the tuple.
 
         """
         if opts is None:
             opts = []
+        else:
+            for opt in opts:
+                if not isinstance(opt, tuple):
+                    raise error.ProgrammingError('opts must be list of tuples')
+                if len(opt) not in (4, 5):
+                    msg = 'each opt tuple must contain 4 or 5 values'
+                    raise error.ProgrammingError(msg)
+
         def dec(wrapper):
             if extension is None:
                 self._commandwrappers.append((command, wrapper, opts))


More information about the Mercurial-devel mailing list