MCPcopy
hub / github.com/tanelpoder/0xtools / _match_argument

Method _match_argument

lib/0xtools/argparse.py:2029–2046  ·  view source on GitHub ↗
(self, action, arg_strings_pattern)

Source from the content-addressed store, hash-verified

2027 return [arg_line]
2028
2029 def _match_argument(self, action, arg_strings_pattern):
2030 # match the pattern for this action to the arg strings
2031 nargs_pattern = self._get_nargs_pattern(action)
2032 match = _re.match(nargs_pattern, arg_strings_pattern)
2033
2034 # raise an exception if we weren't able to find a match
2035 if match is None:
2036 nargs_errors = {
2037 None: _('expected one argument'),
2038 OPTIONAL: _('expected at most one argument'),
2039 ONE_OR_MORE: _('expected at least one argument'),
2040 }
2041 default = _('expected %s argument(s)') % action.nargs
2042 msg = nargs_errors.get(action.nargs, default)
2043 raise ArgumentError(action, msg)
2044
2045 # return the number of arguments matched
2046 return len(match.group(1))
2047
2048 def _match_arguments_partial(self, actions, arg_strings_pattern):
2049 # progressively shorten the actions list by slicing off the

Callers

nothing calls this directly

Calls 2

_get_nargs_patternMethod · 0.95
ArgumentErrorClass · 0.85

Tested by

no test coverage detected