comparison mercurial/dispatch.py @ 16294:795d591b6ef5 stable

alias: abort on missing positional args (issue3331)
author Matt Mackall <mpm@selenic.com>
date Tue, 27 Mar 2012 16:13:59 -0500
parents 1c2aaf05f7d7
children ba42eb722bb3
comparison
equal deleted inserted replaced
16293:bc1d949261c4 16294:795d591b6ef5
216 216
217 return -1 217 return -1
218 218
219 def aliasargs(fn, givenargs): 219 def aliasargs(fn, givenargs):
220 args = getattr(fn, 'args', []) 220 args = getattr(fn, 'args', [])
221 if args and givenargs: 221 if args:
222 cmd = ' '.join(map(util.shellquote, args)) 222 cmd = ' '.join(map(util.shellquote, args))
223 223
224 nums = [] 224 nums = []
225 def replacer(m): 225 def replacer(m):
226 num = int(m.group(1)) - 1 226 num = int(m.group(1)) - 1
227 nums.append(num) 227 nums.append(num)
228 if num < len(givenargs): 228 if num < len(givenargs):
229 return givenargs[num] 229 return givenargs[num]
230 return '' 230 raise util.Abort(_('too few arguments for command alias'))
231 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd) 231 cmd = re.sub(r'\$(\d+|\$)', replacer, cmd)
232 givenargs = [x for i, x in enumerate(givenargs) 232 givenargs = [x for i, x in enumerate(givenargs)
233 if i not in nums] 233 if i not in nums]
234 args = shlex.split(cmd) 234 args = shlex.split(cmd)
235 return args + givenargs 235 return args + givenargs