MCPcopy
hub / github.com/tanelpoder/0xtools / add_subparsers

Method add_subparsers

lib/0xtools/argparse.py:1658–1687  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected