Mercurial > public > mercurial-scm > hg-stable
diff mercurial/fancyopts.py @ 35235:5b569d512fbd
fancyopts: use getopt.gnu_getopt()
The issue described in the docstring has been fixed since Python 20ab2260dc93,
which is in 2.7.
https://hg.python.org/cpython/rev/20ab2260dc93
https://bugs.python.org/issue4458
This fixes the handling of '--' value.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 24 Nov 2017 01:09:00 +0900 |
parents | 4edd2202f7d7 |
children | 98a5aa5575e7 |
line wrap: on
line diff
--- a/mercurial/fancyopts.py Thu Nov 23 23:18:56 2017 +0900 +++ b/mercurial/fancyopts.py Fri Nov 24 01:09:00 2017 +0900 @@ -199,33 +199,6 @@ parsedargs.extend(args[argcount + (not keepsep):]) return parsedopts, parsedargs -def gnugetopt(args, options, longoptions): - """Parse options mostly like getopt.gnu_getopt. - - This is different from getopt.gnu_getopt in that an argument of - will - become an argument of - instead of vanishing completely. - """ - extraargs = [] - if '--' in args: - stopindex = args.index('--') - extraargs = args[stopindex + 1:] - args = args[:stopindex] - opts, parseargs = pycompat.getoptb(args, options, longoptions) - args = [] - while parseargs: - arg = parseargs.pop(0) - if arg and arg[0:1] == '-' and len(arg) > 1: - parseargs.insert(0, arg) - topts, newparseargs = pycompat.getoptb(parseargs,\ - options, longoptions) - opts = opts + topts - parseargs = newparseargs - else: - args.append(arg) - args.extend(extraargs) - return opts, args - - def fancyopts(args, options, state, gnu=False, early=False, optaliases=None): """ read args, parse options, and store options in state @@ -312,7 +285,7 @@ if early: parse = functools.partial(earlygetopt, gnu=gnu) elif gnu: - parse = gnugetopt + parse = pycompat.gnugetoptb else: parse = pycompat.getoptb opts, args = parse(args, shortlist, namelist)