MCPcopy Index your code
hub / github.com/python/cpython / add_parser

Method add_parser

Lib/argparse.py:1318–1357  ·  view source on GitHub ↗
(self, name, *, deprecated=False, **kwargs)

Source from the content-addressed store, hash-verified

1316 metavar=metavar)
1317
1318 def add_parser(self, name, *, deprecated=False, **kwargs):
1319 # set prog from the existing prefix
1320 if kwargs.get('prog') is None:
1321 kwargs['prog'] = '%s %s' % (self._prog_prefix, name)
1322
1323 # set color
1324 if kwargs.get('color') is None:
1325 kwargs['color'] = self._color
1326
1327 aliases = kwargs.pop('aliases', ())
1328
1329 if name in self._name_parser_map:
1330 raise ValueError(f'conflicting subparser: {name}')
1331 for alias in aliases:
1332 if alias in self._name_parser_map:
1333 raise ValueError(f'conflicting subparser alias: {alias}')
1334
1335 # create a pseudo-action to hold the choice help
1336 if 'help' in kwargs:
1337 help = kwargs.pop('help')
1338 choice_action = self._ChoicesPseudoAction(name, aliases, help)
1339 self._choices_actions.append(choice_action)
1340 else:
1341 choice_action = None
1342
1343 # create the parser and add it to the map
1344 parser = self._parser_class(**kwargs)
1345 if choice_action is not None:
1346 parser._check_help(choice_action)
1347 self._name_parser_map[name] = parser
1348
1349 # make parser available under aliases also
1350 for alias in aliases:
1351 self._name_parser_map[alias] = parser
1352
1353 if deprecated:
1354 self._deprecated.add(name)
1355 self._deprecated.update(aliases)
1356
1357 return parser
1358
1359 def _get_subactions(self):
1360 return self._choices_actions

Callers 15

mainFunction · 0.80
add_parserFunction · 0.80
mainFunction · 0.80
parse_argsFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
__main__.pyFile · 0.80
_mainFunction · 0.80
_get_parserMethod · 0.80
test_abbreviationMethod · 0.80

Calls 6

_check_helpMethod · 0.80
getMethod · 0.45
popMethod · 0.45
appendMethod · 0.45
addMethod · 0.45
updateMethod · 0.45