equal
deleted
inserted
replaced
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 from __future__ import absolute_import |
8 from __future__ import absolute_import |
9 |
9 |
10 import getopt |
|
11 |
|
12 from .i18n import _ |
10 from .i18n import _ |
13 from . import error |
11 from . import ( |
|
12 error, |
|
13 pycompat, |
|
14 ) |
14 |
15 |
15 # Set of flags to not apply boolean negation logic on |
16 # Set of flags to not apply boolean negation logic on |
16 nevernegate = set([ |
17 nevernegate = set([ |
17 # avoid --no-noninteractive |
18 # avoid --no-noninteractive |
18 'noninteractive', |
19 'noninteractive', |
32 extraargs = [] |
33 extraargs = [] |
33 if '--' in args: |
34 if '--' in args: |
34 stopindex = args.index('--') |
35 stopindex = args.index('--') |
35 extraargs = args[stopindex + 1:] |
36 extraargs = args[stopindex + 1:] |
36 args = args[:stopindex] |
37 args = args[:stopindex] |
37 opts, parseargs = getopt.getopt(args, options, longoptions) |
38 opts, parseargs = pycompat.getoptb(args, options, longoptions) |
38 args = [] |
39 args = [] |
39 while parseargs: |
40 while parseargs: |
40 arg = parseargs.pop(0) |
41 arg = parseargs.pop(0) |
41 if arg and arg[0] == '-' and len(arg) > 1: |
42 if arg and arg[0] == '-' and len(arg) > 1: |
42 parseargs.insert(0, arg) |
43 parseargs.insert(0, arg) |
43 topts, newparseargs = getopt.getopt(parseargs, options, longoptions) |
44 topts, newparseargs = pycompat.getoptb(parseargs,\ |
|
45 options, longoptions) |
44 opts = opts + topts |
46 opts = opts + topts |
45 parseargs = newparseargs |
47 parseargs = newparseargs |
46 else: |
48 else: |
47 args.append(arg) |
49 args.append(arg) |
48 args.extend(extraargs) |
50 args.extend(extraargs) |
123 |
125 |
124 # parse arguments |
126 # parse arguments |
125 if gnu: |
127 if gnu: |
126 parse = gnugetopt |
128 parse = gnugetopt |
127 else: |
129 else: |
128 parse = getopt.getopt |
130 parse = pycompat.getoptb |
129 opts, args = parse(args, shortlist, namelist) |
131 opts, args = parse(args, shortlist, namelist) |
130 |
132 |
131 # transfer result to state |
133 # transfer result to state |
132 for opt, val in opts: |
134 for opt, val in opts: |
133 boolval = True |
135 boolval = True |