comparison mercurial/exthelper.py @ 41060:7250cbaabde0

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 23 Dec 2018 21:54:56 -0500
parents f7863606d4ff
children 0358cca1dccf
comparison
equal deleted inserted replaced
41059:0ecf58f7c2b2 41060:7250cbaabde0
11 11
12 from __future__ import absolute_import 12 from __future__ import absolute_import
13 13
14 from . import ( 14 from . import (
15 commands, 15 commands,
16 error,
16 extensions, 17 extensions,
17 registrar, 18 registrar,
18 ) 19 )
19 20
20 class exthelper(object): 21 class exthelper(object):
78 for cont, funcname, func in self._duckpunchers: 79 for cont, funcname, func in self._duckpunchers:
79 setattr(cont, funcname, func) 80 setattr(cont, funcname, func)
80 for command, wrapper, opts in self._commandwrappers: 81 for command, wrapper, opts in self._commandwrappers:
81 entry = extensions.wrapcommand(commands.table, command, wrapper) 82 entry = extensions.wrapcommand(commands.table, command, wrapper)
82 if opts: 83 if opts:
83 for short, long, val, msg in opts: 84 for opt in opts:
84 entry[1].append((short, long, val, msg)) 85 entry[1].append(opt)
85 for cont, funcname, wrapper in self._functionwrappers: 86 for cont, funcname, wrapper in self._functionwrappers:
86 extensions.wrapfunction(cont, funcname, wrapper) 87 extensions.wrapfunction(cont, funcname, wrapper)
87 for c in self._uicallables: 88 for c in self._uicallables:
88 c(ui) 89 c(ui)
89 90
119 # it. 120 # it.
120 continue 121 continue
121 knownexts[ext] = e.cmdtable 122 knownexts[ext] = e.cmdtable
122 entry = extensions.wrapcommand(knownexts[ext], command, wrapper) 123 entry = extensions.wrapcommand(knownexts[ext], command, wrapper)
123 if opts: 124 if opts:
124 for short, long, val, msg in opts: 125 for opt in opts:
125 entry[1].append((short, long, val, msg)) 126 entry[1].append(opt)
126 127
127 for c in self._extcallables: 128 for c in self._extcallables:
128 c(ui) 129 c(ui)
129 130
130 def finalreposetup(self, ui, repo): 131 def finalreposetup(self, ui, repo):
204 @eh.wrapcommand('summary') 205 @eh.wrapcommand('summary')
205 def wrapsummary(orig, ui, repo, *args, **kwargs): 206 def wrapsummary(orig, ui, repo, *args, **kwargs):
206 ui.note('Barry!') 207 ui.note('Barry!')
207 return orig(ui, repo, *args, **kwargs) 208 return orig(ui, repo, *args, **kwargs)
208 209
209 The `opts` argument allows specifying additional arguments for the 210 The `opts` argument allows specifying a list of tuples for additional
210 command. 211 arguments for the command. See ``mercurial.fancyopts.fancyopts()`` for
212 the format of the tuple.
211 213
212 """ 214 """
213 if opts is None: 215 if opts is None:
214 opts = [] 216 opts = []
217 else:
218 for opt in opts:
219 if not isinstance(opt, tuple):
220 raise error.ProgrammingError('opts must be list of tuples')
221 if len(opt) not in (4, 5):
222 msg = 'each opt tuple must contain 4 or 5 values'
223 raise error.ProgrammingError(msg)
224
215 def dec(wrapper): 225 def dec(wrapper):
216 if extension is None: 226 if extension is None:
217 self._commandwrappers.append((command, wrapper, opts)) 227 self._commandwrappers.append((command, wrapper, opts))
218 else: 228 else:
219 self._extcommandwrappers.append((extension, command, wrapper, 229 self._extcommandwrappers.append((extension, command, wrapper,