Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 19099:fc081623f4bd stable
dispatch: add support for --option=value to _earlygetopt
This fixes a very confusing error message:
$ hg --config=pager.enabled=off st
abort: option --config may not be abbreviated!
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Mon, 29 Apr 2013 14:14:42 -0700 |
parents | f01ae031f84c |
children | 41e39a0299cb |
comparison
equal
deleted
inserted
replaced
19098:f01ae031f84c | 19099:fc081623f4bd |
---|---|
488 | 488 |
489 >>> args = ['x', '--cwd', 'foo', 'y'] | 489 >>> args = ['x', '--cwd', 'foo', 'y'] |
490 >>> _earlygetopt(['--cwd'], args), args | 490 >>> _earlygetopt(['--cwd'], args), args |
491 (['foo'], ['x', 'y']) | 491 (['foo'], ['x', 'y']) |
492 | 492 |
493 >>> args = ['x', '--cwd=bar', 'y'] | |
494 >>> _earlygetopt(['--cwd'], args), args | |
495 (['bar'], ['x', 'y']) | |
496 | |
493 >>> args = ['x', '-R', 'foo', 'y'] | 497 >>> args = ['x', '-R', 'foo', 'y'] |
494 >>> _earlygetopt(['-R'], args), args | 498 >>> _earlygetopt(['-R'], args), args |
495 (['foo'], ['x', 'y']) | 499 (['foo'], ['x', 'y']) |
496 | 500 |
497 >>> args = ['x', '-Rbar', 'y'] | 501 >>> args = ['x', '-Rbar', 'y'] |
504 argcount = len(args) | 508 argcount = len(args) |
505 shortopts = [opt for opt in aliases if len(opt) == 2] | 509 shortopts = [opt for opt in aliases if len(opt) == 2] |
506 values = [] | 510 values = [] |
507 pos = 0 | 511 pos = 0 |
508 while pos < argcount: | 512 while pos < argcount: |
509 if args[pos] in aliases: | 513 fullarg = arg = args[pos] |
510 if pos + 1 >= argcount: | 514 equals = arg.find('=') |
511 # ignore and let getopt report an error if there is no value | 515 if equals > -1: |
512 break | 516 arg = arg[:equals] |
517 if arg in aliases: | |
513 del args[pos] | 518 del args[pos] |
514 values.append(args.pop(pos)) | 519 if equals > -1: |
515 argcount -= 2 | 520 values.append(fullarg[equals + 1:]) |
516 elif args[pos][:2] in shortopts: | 521 argcount -= 1 |
522 else: | |
523 if pos + 1 >= argcount: | |
524 # ignore and let getopt report an error if there is no value | |
525 break | |
526 values.append(args.pop(pos)) | |
527 argcount -= 2 | |
528 elif arg[:2] in shortopts: | |
517 # short option can have no following space, e.g. hg log -Rfoo | 529 # short option can have no following space, e.g. hg log -Rfoo |
518 values.append(args.pop(pos)[2:]) | 530 values.append(args.pop(pos)[2:]) |
519 argcount -= 1 | 531 argcount -= 1 |
520 else: | 532 else: |
521 pos += 1 | 533 pos += 1 |