MCPcopy Create free account
hub / github.com/apache/madlib / _get_nargs_pattern

Method _get_nargs_pattern

src/madpack/argparse.py:2155–2194  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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

Callers 2

_match_argumentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected