comparison mercurial/registrar.py @ 32377:ec84db232fc2

registrar: switch @command decorator to class It overrides _funcregistrarbase._doregister() since the structure of the command table is quite different.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 08 May 2017 22:08:40 +0900
parents 46ba2cdda476
children 92de09a05d7f
comparison
equal deleted inserted replaced
32376:46ba2cdda476 32377:ec84db232fc2
94 def _extrasetup(self, name, func): 94 def _extrasetup(self, name, func):
95 """Execute exra setup for registered function, if needed 95 """Execute exra setup for registered function, if needed
96 """ 96 """
97 pass 97 pass
98 98
99 def command(table): 99 class command(_funcregistrarbase):
100 """Returns a function object to be used as a decorator for making commands. 100 """Decorator to register a command function to table
101 101
102 This function receives a command table as its argument. The table should 102 This class receives a command table as its argument. The table should
103 be a dict. 103 be a dict.
104 104
105 The returned function can be used as a decorator for adding commands 105 The created object can be used as a decorator for adding commands to
106 to that command table. This function accepts multiple arguments to define 106 that command table. This accepts multiple arguments to define a command.
107 a command.
108 107
109 The first argument is the command name. 108 The first argument is the command name.
110 109
111 The options argument is an iterable of tuples defining command arguments. 110 The options argument is an iterable of tuples defining command arguments.
112 See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. 111 See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple.
124 The inferrepo argument defines whether to try to find a repository from the 123 The inferrepo argument defines whether to try to find a repository from the
125 command line arguments. If True, arguments will be examined for potential 124 command line arguments. If True, arguments will be examined for potential
126 repository locations. See ``findrepo()``. If a repository is found, it 125 repository locations. See ``findrepo()``. If a repository is found, it
127 will be used. 126 will be used.
128 """ 127 """
129 def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False, 128
130 inferrepo=False): 129 def _doregister(self, func, name, options=(), synopsis=None,
131 def decorator(func): 130 norepo=False, optionalrepo=False, inferrepo=False):
131 if True:
132 func.norepo = norepo 132 func.norepo = norepo
133 func.optionalrepo = optionalrepo 133 func.optionalrepo = optionalrepo
134 func.inferrepo = inferrepo 134 func.inferrepo = inferrepo
135 if synopsis: 135 if synopsis:
136 table[name] = func, list(options), synopsis 136 self._table[name] = func, list(options), synopsis
137 else: 137 else:
138 table[name] = func, list(options) 138 self._table[name] = func, list(options)
139 return func 139 return func
140 return decorator
141
142 return cmd
143 140
144 class revsetpredicate(_funcregistrarbase): 141 class revsetpredicate(_funcregistrarbase):
145 """Decorator to register revset predicate 142 """Decorator to register revset predicate
146 143
147 Usage:: 144 Usage::