MCPcopy Index your code
hub / github.com/tanelpoder/0xtools / _get_nargs_pattern

Method _get_nargs_pattern

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

Source from the content-addressed store, hash-verified

2163 return result
2164
2165 def _get_nargs_pattern(self, action):
2166 # in all examples below, we have to allow for '--' args
2167 # which are represented as '-' in the pattern
2168 nargs = action.nargs
2169
2170 # the default (None) is assumed to be a single argument
2171 if nargs is None:
2172 nargs_pattern = '(-*A-*)'
2173
2174 # allow zero or one arguments
2175 elif nargs == OPTIONAL:
2176 nargs_pattern = '(-*A?-*)'
2177
2178 # allow zero or more arguments
2179 elif nargs == ZERO_OR_MORE:
2180 nargs_pattern = '(-*[A-]*)'
2181
2182 # allow one or more arguments
2183 elif nargs == ONE_OR_MORE:
2184 nargs_pattern = '(-*A[A-]*)'
2185
2186 # allow any number of options or arguments
2187 elif nargs == REMAINDER:
2188 nargs_pattern = '([-AO]*)'
2189
2190 # allow one argument followed by any number of options or arguments
2191 elif nargs == PARSER:
2192 nargs_pattern = '(-*A[-AO]*)'
2193
2194 # all others should be integers
2195 else:
2196 nargs_pattern = '(-*%s-*)' % '-*'.join('A' * nargs)
2197
2198 # if this is an optional action, -- is not allowed
2199 if action.option_strings:
2200 nargs_pattern = nargs_pattern.replace('-*', '')
2201 nargs_pattern = nargs_pattern.replace('-', '')
2202
2203 # return the pattern
2204 return nargs_pattern
2205
2206 # ========================
2207 # Value conversion methods

Callers 2

_match_argumentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected