Mercurial > hg-stable
diff mercurial/fancyopts.py @ 35236:98a5aa5575e7
fancyopts: fix handling of "--" value in earlygetopt()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 25 Nov 2017 17:30:50 +0900 |
parents | 5b569d512fbd |
children | cc9d0763c8e9 |
line wrap: on
line diff
--- a/mercurial/fancyopts.py Fri Nov 24 01:09:00 2017 +0900 +++ b/mercurial/fancyopts.py Sat Nov 25 17:30:50 2017 +0900 @@ -119,7 +119,7 @@ >>> get([b'--cwd=foo', b'x', b'y', b'-R', b'bar', b'--debugger'], gnu=False) ([('--cwd', 'foo')], ['x', 'y', '-R', 'bar', '--debugger']) >>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=False) - ([], ['--unknown', '--cwd=foo', '--debugger']) + ([], ['--unknown', '--cwd=foo', '--', '--debugger']) stripping early options (without loosing '--'): @@ -141,6 +141,13 @@ >>> get([b'-q', b'--']) ([('-q', '')], []) + '--' may be a value: + + >>> get([b'-R', b'--', b'x']) + ([('-R', '--')], ['x']) + >>> get([b'--cwd', b'--', b'x']) + ([('--cwd', '--')], ['x']) + value passed to bool options: >>> get([b'--debugger=foo', b'x']) @@ -163,20 +170,16 @@ >>> get([b'-', b'y']) ([], ['-', 'y']) """ - # ignoring everything just after '--' isn't correct as '--' may be an - # option value (e.g. ['-R', '--']), but we do that consistently. - try: - argcount = args.index('--') - except ValueError: - argcount = len(args) - parsedopts = [] parsedargs = [] pos = 0 - while pos < argcount: + while pos < len(args): arg = args[pos] + if arg == '--': + pos += not keepsep + break flag, hasval, val, takeval = _earlyoptarg(arg, shortlist, namelist) - if not hasval and takeval and pos + 1 >= argcount: + if not hasval and takeval and pos + 1 >= len(args): # missing last argument break if not flag or hasval and not takeval: @@ -195,8 +198,7 @@ parsedopts.append((flag, args[pos + 1])) pos += 2 - parsedargs.extend(args[pos:argcount]) - parsedargs.extend(args[argcount + (not keepsep):]) + parsedargs.extend(args[pos:]) return parsedopts, parsedargs def fancyopts(args, options, state, gnu=False, early=False, optaliases=None):