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

Method add_argument

src/madpack/argparse.py:1278–1316  ·  view source on GitHub ↗

add_argument(dest, ..., name=value, ...) add_argument(option_string, option_string, ..., name=value, ...)

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

1276 # Adding argument actions
1277 # =======================
1278 def add_argument(self, *args, **kwargs):
1279 """
1280 add_argument(dest, ..., name=value, ...)
1281 add_argument(option_string, option_string, ..., name=value, ...)
1282 """
1283
1284 # if no positional args are supplied or only one is supplied and
1285 # it doesn't look like an option string, parse a positional
1286 # argument
1287 chars = self.prefix_chars
1288 if not args or len(args) == 1 and args[0][0] not in chars:
1289 if args and 'dest' in kwargs:
1290 raise ValueError('dest supplied twice for positional argument')
1291 kwargs = self._get_positional_kwargs(*args, **kwargs)
1292
1293 # otherwise, we're adding an optional argument
1294 else:
1295 kwargs = self._get_optional_kwargs(*args, **kwargs)
1296
1297 # if no default was supplied, use the parser-level default
1298 if 'default' not in kwargs:
1299 dest = kwargs['dest']
1300 if dest in self._defaults:
1301 kwargs['default'] = self._defaults[dest]
1302 elif self.argument_default is not None:
1303 kwargs['default'] = self.argument_default
1304
1305 # create the action object, and add it to the parser
1306 action_class = self._pop_action_class(kwargs)
1307 if not _callable(action_class):
1308 raise ValueError('unknown action "%s"' % action_class)
1309 action = action_class(**kwargs)
1310
1311 # raise an error if the action type is not callable
1312 type_func = self._registry_get('type', action.type, action.type)
1313 if not _callable(type_func):
1314 raise ValueError('%r is not callable' % type_func)
1315
1316 return self._add_action(action)
1317
1318 def add_argument_group(self, *args, **kwargs):
1319 group = _ArgumentGroup(self, *args, **kwargs)

Callers

nothing calls this directly

Calls 6

_get_optional_kwargsMethod · 0.95
_pop_action_classMethod · 0.95
_registry_getMethod · 0.95
_add_actionMethod · 0.95
_callableFunction · 0.85

Tested by

no test coverage detected