registrar: switch @command decorator to class
It overrides _funcregistrarbase._doregister() since the structure of the
command table is quite different.
--- a/mercurial/registrar.py Sat Jan 09 23:07:20 2016 +0900
+++ b/mercurial/registrar.py Mon May 08 22:08:40 2017 +0900
@@ -96,15 +96,14 @@
"""
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 @@
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