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

Method add_subparsers

src/madpack/argparse.py:1659–1688  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

1657 # Optional/Positional adding methods
1658 # ==================================
1659 def add_subparsers(self, **kwargs):
1660 if self._subparsers is not None:
1661 self.error(_('cannot have multiple subparser arguments'))
1662
1663 # add the parser class to the arguments if it's not present
1664 kwargs.setdefault('parser_class', type(self))
1665
1666 if 'title' in kwargs or 'description' in kwargs:
1667 title = _(kwargs.pop('title', 'subcommands'))
1668 description = _(kwargs.pop('description', None))
1669 self._subparsers = self.add_argument_group(title, description)
1670 else:
1671 self._subparsers = self._positionals
1672
1673 # prog defaults to the usage message of this parser, skipping
1674 # optional arguments and with no "usage:" prefix
1675 if kwargs.get('prog') is None:
1676 formatter = self._get_formatter()
1677 positionals = self._get_positional_actions()
1678 groups = self._mutually_exclusive_groups
1679 formatter.add_usage(self.usage, positionals, groups, '')
1680 kwargs['prog'] = formatter.format_help().strip()
1681
1682 # create the parsers action and add it to the positionals list
1683 parsers_class = self._pop_action_class(kwargs, 'parsers')
1684 action = parsers_class(option_strings=[], **kwargs)
1685 self._subparsers._add_action(action)
1686
1687 # return the created parsers action
1688 return action
1689
1690 def _add_action(self, action):
1691 if action.option_strings:

Callers

nothing calls this directly

Calls 9

errorMethod · 0.95
_get_formatterMethod · 0.95
add_argument_groupMethod · 0.80
add_usageMethod · 0.80
_pop_action_classMethod · 0.80
getMethod · 0.45
format_helpMethod · 0.45
_add_actionMethod · 0.45

Tested by

no test coverage detected