[PATCH 3 of 6] registrar: switch @command decorator to class
Yuya Nishihara
yuya at tcha.org
Sat May 13 05:57:34 EDT 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1494248920 -32400
# Mon May 08 22:08:40 2017 +0900
# Node ID 2a4face2522bf8733d681b4b475128715c0eea38
# Parent 384fb01cd80e7f7ad58235113768eff72d7dbf4e
registrar: switch @command decorator to class
It overrides _funcregistrarbase._doregister() since the structure of the
command table is quite different.
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
More information about the Mercurial-devel
mailing list