MCPcopy
hub / github.com/docopt/docopt / parse_shorts

Function parse_shorts

docopt.py:335–367  ·  view source on GitHub ↗

shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;

(tokens, options)

Source from the content-addressed store, hash-verified

333
334
335def parse_shorts(tokens, options):
336 """shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;"""
337 token = tokens.move()
338 assert token.startswith('-') and not token.startswith('--')
339 left = token.lstrip('-')
340 parsed = []
341 while left != '':
342 short, left = '-' + left[0], left[1:]
343 similar = [o for o in options if o.short == short]
344 if len(similar) > 1:
345 raise tokens.error('%s is specified ambiguously %d times' %
346 (short, len(similar)))
347 elif len(similar) < 1:
348 o = Option(short, None, 0)
349 options.append(o)
350 if tokens.error is DocoptExit:
351 o = Option(short, None, 0, True)
352 else: # why copying is necessary here?
353 o = Option(short, similar[0].long,
354 similar[0].argcount, similar[0].value)
355 value = None
356 if o.argcount != 0:
357 if left == '':
358 if tokens.current() is None:
359 raise tokens.error('%s requires argument' % short)
360 value = tokens.move()
361 else:
362 value = left
363 left = ''
364 if tokens.error is DocoptExit:
365 o.value = value if value is not None else True
366 parsed.append(o)
367 return parsed
368
369
370def parse_pattern(source, 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…