MCPcopy
hub / github.com/docopt/docopt / Option

Class Option

docopt.py:186–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184
185
186class Option(ChildPattern):
187
188 def __init__(self, short=None, long=None, argcount=0, value=False):
189 assert argcount in (0, 1)
190 self.short, self.long = short, long
191 self.argcount, self.value = argcount, value
192 self.value = None if value is False and argcount else value
193
194 @classmethod
195 def parse(class_, option_description):
196 short, long, argcount, value = None, None, 0, False
197 options, _, description = option_description.strip().partition(' ')
198 options = options.replace(',', ' ').replace('=', ' ')
199 for s in options.split():
200 if s.startswith('--'):
201 long = s
202 elif s.startswith('-'):
203 short = s
204 else:
205 argcount = 1
206 if argcount:
207 matched = re.findall('\[default: (.*)\]', description, flags=re.I)
208 value = matched[0] if matched else None
209 return class_(short, long, argcount, value)
210
211 def single_match(self, left):
212 for n, p in enumerate(left):
213 if self.name == p.name:
214 return n, p
215 return None, None
216
217 @property
218 def name(self):
219 return self.long or self.short
220
221 def __repr__(self):
222 return 'Option(%r, %r, %r, %r)' % (self.short, self.long,
223 self.argcount, self.value)
224
225
226class Required(ParentPattern):

Callers 15

test_pattern_flatFunction · 0.90
test_optionFunction · 0.90
test_option_nameFunction · 0.90
test_parse_argvFunction · 0.90
test_parse_patternFunction · 0.90
test_option_matchFunction · 0.90
test_argument_matchFunction · 0.90
test_command_matchFunction · 0.90
test_optional_matchFunction · 0.90
test_required_matchFunction · 0.90
test_either_matchFunction · 0.90
test_one_or_more_matchFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_pattern_flatFunction · 0.72
test_optionFunction · 0.72
test_option_nameFunction · 0.72
test_parse_argvFunction · 0.72
test_parse_patternFunction · 0.72
test_option_matchFunction · 0.72
test_argument_matchFunction · 0.72
test_command_matchFunction · 0.72
test_optional_matchFunction · 0.72
test_required_matchFunction · 0.72
test_either_matchFunction · 0.72
test_one_or_more_matchFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…