Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 14265:e4ab5ae193f2
add positional arguments to non-shell aliases
author | Alexander Solovyov <alexander@solovyov.net> |
---|---|
date | Sun, 01 May 2011 12:29:32 +0200 |
parents | dea93484cf9f |
children | 005a540e9aee |
comparison
equal
deleted
inserted
replaced
14264:8e00906066c9 | 14265:e4ab5ae193f2 |
---|---|
180 % ", ".join([x[0] for x in extensions.extensions()])) | 180 % ", ".join([x[0] for x in extensions.extensions()])) |
181 raise | 181 raise |
182 | 182 |
183 return -1 | 183 return -1 |
184 | 184 |
185 def aliasargs(fn): | 185 def aliasargs(fn, givenargs): |
186 if hasattr(fn, 'args'): | 186 args = getattr(fn, 'args', []) |
187 return fn.args | 187 if args and givenargs: |
188 return [] | 188 cmd = ' '.join(map(util.shellquote, args)) |
189 | |
190 nums = [] | |
191 def replacer(m): | |
192 num = int(m.group(1)) - 1 | |
193 nums.append(num) | |
194 return givenargs[num] | |
195 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd) | |
196 givenargs = [x for i, x in enumerate(givenargs) | |
197 if i not in nums] | |
198 args = shlex.split(cmd) | |
199 return args + givenargs | |
189 | 200 |
190 class cmdalias(object): | 201 class cmdalias(object): |
191 def __init__(self, name, definition, cmdtable): | 202 def __init__(self, name, definition, cmdtable): |
192 self.name = self.cmd = name | 203 self.name = self.cmd = name |
193 self.cmdname = '' | 204 self.cmdname = '' |
261 if len(tableentry) > 2: | 272 if len(tableentry) > 2: |
262 self.fn, self.opts, self.help = tableentry | 273 self.fn, self.opts, self.help = tableentry |
263 else: | 274 else: |
264 self.fn, self.opts = tableentry | 275 self.fn, self.opts = tableentry |
265 | 276 |
266 self.args = aliasargs(self.fn) + args | 277 self.args = aliasargs(self.fn, args) |
267 if cmd not in commands.norepo.split(' '): | 278 if cmd not in commands.norepo.split(' '): |
268 self.norepo = False | 279 self.norepo = False |
269 if self.help.startswith("hg " + cmd): | 280 if self.help.startswith("hg " + cmd): |
270 # drop prefix in old-style help lines so hg shows the alias | 281 # drop prefix in old-style help lines so hg shows the alias |
271 self.help = self.help[4 + len(cmd):] | 282 self.help = self.help[4 + len(cmd):] |
328 if args: | 339 if args: |
329 cmd, args = args[0], args[1:] | 340 cmd, args = args[0], args[1:] |
330 aliases, entry = cmdutil.findcmd(cmd, commands.table, | 341 aliases, entry = cmdutil.findcmd(cmd, commands.table, |
331 ui.config("ui", "strict")) | 342 ui.config("ui", "strict")) |
332 cmd = aliases[0] | 343 cmd = aliases[0] |
333 args = aliasargs(entry[0]) + args | 344 args = aliasargs(entry[0], args) |
334 defaults = ui.config("defaults", cmd) | 345 defaults = ui.config("defaults", cmd) |
335 if defaults: | 346 if defaults: |
336 args = map(util.expandpath, shlex.split(defaults)) + args | 347 args = map(util.expandpath, shlex.split(defaults)) + args |
337 c = list(entry[1]) | 348 c = list(entry[1]) |
338 else: | 349 else: |