MCPcopy
hub / github.com/docopt/docopt / parse_long

Function parse_long

docopt.py:302–332  ·  view source on GitHub ↗

long ::= '--' chars [ ( ' ' | '=' ) chars ] ;

(tokens, options)

Source from the content-addressed store, hash-verified

300
301
302def parse_long(tokens, options):
303 """long ::= '--' chars [ ( ' ' | '=' ) chars ] ;"""
304 long, eq, value = tokens.move().partition('=')
305 assert long.startswith('--')
306 value = None if eq == value == '' else value
307 similar = [o for o in options if o.long == long]
308 if tokens.error is DocoptExit and similar == []: # if no exact match
309 similar = [o for o in options if o.long and o.long.startswith(long)]
310 if len(similar) > 1: # might be simply specified ambiguously 2+ times?
311 raise tokens.error('%s is not a unique prefix: %s?' %
312 (long, ', '.join(o.long for o in similar)))
313 elif len(similar) < 1:
314 argcount = 1 if eq == '=' else 0
315 o = Option(None, long, argcount)
316 options.append(o)
317 if tokens.error is DocoptExit:
318 o = Option(None, long, argcount, value if argcount else True)
319 else:
320 o = Option(similar[0].short, similar[0].long,
321 similar[0].argcount, similar[0].value)
322 if o.argcount == 0:
323 if value is not None:
324 raise tokens.error('%s must not have an argument' % o.long)
325 else:
326 if value is None:
327 if tokens.current() is None:
328 raise tokens.error('%s requires argument' % o.long)
329 value = tokens.move()
330 if tokens.error is DocoptExit:
331 o.value = value if value is not None else True
332 return [o]
333
334
335def parse_shorts(tokens, options):

Callers 2

parse_atomFunction · 0.85
parse_argvFunction · 0.85

Calls 3

OptionClass · 0.85
moveMethod · 0.80
currentMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…