246 except (IndexError, ValueError): |
246 except (IndexError, ValueError): |
247 raise util.Abort(_('malformed --config option: %s') % cfg) |
247 raise util.Abort(_('malformed --config option: %s') % cfg) |
248 return parsed |
248 return parsed |
249 |
249 |
250 def earlygetopt(aliases, args): |
250 def earlygetopt(aliases, args): |
251 """Return list of values for a option (with aliases) in given order""" |
251 """Return list of values for a option (with aliases) in given order |
|
252 |
|
253 Short option aliases have to occur before long aliases, e.g.: |
|
254 earlygetopt(["-R", "--repository", "--repo"], args) |
|
255 (this is not checked!) |
|
256 """ |
252 try: |
257 try: |
253 argcount = args.index("--") |
258 argcount = args.index("--") |
254 except ValueError: |
259 except ValueError: |
255 argcount = len(args) |
260 argcount = len(args) |
256 values = [] |
261 values = [] |
257 pos = 0 |
262 pos = 0 |
258 while pos < argcount: |
263 while pos < argcount: |
259 valuepos = argcount |
264 valuepos = argcount |
260 for opt in aliases: |
265 for opt in aliases: |
|
266 # short option can have no spaces, e.g. hg log -qRfoo: |
|
267 if len(opt) == 2: |
|
268 i = argcount |
|
269 while i > 0: |
|
270 i -= 1 |
|
271 arg = args[i] |
|
272 if len(arg) > 2 and arg[0] == '-' and arg[1] != '-': |
|
273 optpos = arg.find(opt[1]) |
|
274 # split Rfoo -> R foo |
|
275 if 0 < optpos < len(arg)-1: |
|
276 args[i:i+1] = [arg[:optpos+1], arg[optpos+1:]] |
|
277 argcount += 1 |
|
278 # split -qR -> -q -R |
|
279 if optpos > 1: |
|
280 args[i:i+1] = [arg[:optpos], opt] |
|
281 argcount += 1 |
261 # find next occurance of current alias |
282 # find next occurance of current alias |
262 try: |
283 try: |
263 candidate = args.index(opt, pos, argcount) + 1 |
284 candidate = args.index(opt, pos, argcount) + 1 |
264 # ignore and let getopt report an error if there is no value |
285 # ignore and let getopt report an error if there is no value |
265 if candidate < valuepos: |
286 if candidate < valuepos: |