##// END OF EJS Templates
fancyopts: use getopt.gnu_getopt()...
Yuya Nishihara -
r35226:5b569d51 default
parent child Browse files
Show More
@@ -199,33 +199,6 b' def earlygetopt(args, shortlist, namelis'
199 199 parsedargs.extend(args[argcount + (not keepsep):])
200 200 return parsedopts, parsedargs
201 201
202 def gnugetopt(args, options, longoptions):
203 """Parse options mostly like getopt.gnu_getopt.
204
205 This is different from getopt.gnu_getopt in that an argument of - will
206 become an argument of - instead of vanishing completely.
207 """
208 extraargs = []
209 if '--' in args:
210 stopindex = args.index('--')
211 extraargs = args[stopindex + 1:]
212 args = args[:stopindex]
213 opts, parseargs = pycompat.getoptb(args, options, longoptions)
214 args = []
215 while parseargs:
216 arg = parseargs.pop(0)
217 if arg and arg[0:1] == '-' and len(arg) > 1:
218 parseargs.insert(0, arg)
219 topts, newparseargs = pycompat.getoptb(parseargs,\
220 options, longoptions)
221 opts = opts + topts
222 parseargs = newparseargs
223 else:
224 args.append(arg)
225 args.extend(extraargs)
226 return opts, args
227
228
229 202 def fancyopts(args, options, state, gnu=False, early=False, optaliases=None):
230 203 """
231 204 read args, parse options, and store options in state
@@ -312,7 +285,7 b' def fancyopts(args, options, state, gnu='
312 285 if early:
313 286 parse = functools.partial(earlygetopt, gnu=gnu)
314 287 elif gnu:
315 parse = gnugetopt
288 parse = pycompat.gnugetoptb
316 289 else:
317 290 parse = pycompat.getoptb
318 291 opts, args = parse(args, shortlist, namelist)
@@ -214,7 +214,7 b' if ispy3:'
214 214 def open(name, mode='r', buffering=-1):
215 215 return builtins.open(name, sysstr(mode), buffering)
216 216
217 def getoptb(args, shortlist, namelist):
217 def _getoptbwrapper(orig, args, shortlist, namelist):
218 218 """
219 219 Takes bytes arguments, converts them to unicode, pass them to
220 220 getopt.getopt(), convert the returned values back to bytes and then
@@ -224,7 +224,7 b' if ispy3:'
224 224 args = [a.decode('latin-1') for a in args]
225 225 shortlist = shortlist.decode('latin-1')
226 226 namelist = [a.decode('latin-1') for a in namelist]
227 opts, args = getopt.getopt(args, shortlist, namelist)
227 opts, args = orig(args, shortlist, namelist)
228 228 opts = [(a[0].encode('latin-1'), a[1].encode('latin-1'))
229 229 for a in opts]
230 230 args = [a.encode('latin-1') for a in args]
@@ -291,8 +291,8 b' else:'
291 291 def getdoc(obj):
292 292 return getattr(obj, '__doc__', None)
293 293
294 def getoptb(args, shortlist, namelist):
295 return getopt.getopt(args, shortlist, namelist)
294 def _getoptbwrapper(orig, args, shortlist, namelist):
295 return orig(args, shortlist, namelist)
296 296
297 297 strkwargs = identity
298 298 byteskwargs = identity
@@ -320,3 +320,9 b" isjython = sysplatform.startswith('java'"
320 320 isdarwin = sysplatform == 'darwin'
321 321 isposix = osname == 'posix'
322 322 iswindows = osname == 'nt'
323
324 def getoptb(args, shortlist, namelist):
325 return _getoptbwrapper(getopt.getopt, args, shortlist, namelist)
326
327 def gnugetoptb(args, shortlist, namelist):
328 return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
@@ -37,10 +37,17 b' Missing parameter for early option:'
37 37 hg log [OPTION]... [FILE]
38 38 (use 'hg log -h' to show more help)
39 39
40 $ hg log -R -- 2>&1 | grep 'hg log'
41 hg log: option -R requires argument
42 hg log [OPTION]... [FILE]
43 (use 'hg log -h' to show more help)
40 "--" may be an option value:
41
42 $ hg -R -- log
43 abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo!
44 [255]
45 $ hg log -R --
46 abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo!
47 [255]
48 $ hg log -T --
49 -- (no-eol)
50 $ hg log -T -- -k nomatch
44 51
45 52 Parsing of early options should stop at "--":
46 53
General Comments 0
You need to be logged in to leave comments. Login now