Patchwork [3,of,8,V2] registrar: switch @command decorator to class

login
register
mail settings
Submitter Yuya Nishihara
Date May 19, 2017, 3:25 p.m.
Message ID <3317964fa88c21a59e71.1495207513@mimosa>
Download mbox | patch
Permalink /patch/20722/
State Accepted
Headers show

Comments

Yuya Nishihara - May 19, 2017, 3:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1494248920 -32400
#      Mon May 08 22:08:40 2017 +0900
# Node ID 3317964fa88c21a59e7181228773f63ac27480eb
# Parent  cda425df1285840b30421dfa1959a6757855137a
registrar: switch @command decorator to class

It overrides _funcregistrarbase._doregister() since the structure of the
command table is quite different.

Patch

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -96,15 +96,14 @@  class _funcregistrarbase(object):
         """
         pass
 
-def command(table):
-    """Returns a function object to be used as a decorator for making commands.
+class command(_funcregistrarbase):
+    """Decorator to register a command function to table
 
-    This function receives a command table as its argument. The table should
+    This class receives a command table as its argument. The table should
     be a dict.
 
-    The returned function can be used as a decorator for adding commands
-    to that command table. This function accepts multiple arguments to define
-    a command.
+    The created object can be used as a decorator for adding commands to
+    that command table. This accepts multiple arguments to define a command.
 
     The first argument is the command name.
 
@@ -126,20 +125,18 @@  def command(table):
     repository locations. See ``findrepo()``. If a repository is found, it
     will be used.
     """
-    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
-            inferrepo=False):
-        def decorator(func):
+
+    def _doregister(self, func, name, options=(), synopsis=None,
+                    norepo=False, optionalrepo=False, inferrepo=False):
+        if True:
             func.norepo = norepo
             func.optionalrepo = optionalrepo
             func.inferrepo = inferrepo
             if synopsis:
-                table[name] = func, list(options), synopsis
+                self._table[name] = func, list(options), synopsis
             else:
-                table[name] = func, list(options)
+                self._table[name] = func, list(options)
             return func
-        return decorator
-
-    return cmd
 
 class revsetpredicate(_funcregistrarbase):
     """Decorator to register revset predicate