MCPcopy Index your code
hub / github.com/RustPython/RustPython / add_subparsers

Method add_subparsers

Lib/argparse.py:1946–1979  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

1944 # ==================================
1945
1946 def add_subparsers(self, **kwargs):
1947 if self._subparsers is not None:
1948 raise ValueError('cannot have multiple subparser arguments')
1949
1950 # add the parser class to the arguments if it's not present
1951 kwargs.setdefault('parser_class', type(self))
1952
1953 if 'title' in kwargs or 'description' in kwargs:
1954 title = kwargs.pop('title', _('subcommands'))
1955 description = kwargs.pop('description', None)
1956 self._subparsers = self.add_argument_group(title, description)
1957 else:
1958 self._subparsers = self._positionals
1959
1960 # prog defaults to the usage message of this parser, skipping
1961 # optional arguments and with no "usage:" prefix
1962 if kwargs.get('prog') is None:
1963 # Create formatter without color to avoid storing ANSI codes in prog
1964 formatter = self.formatter_class(prog=self.prog)
1965 formatter._set_color(False)
1966 positionals = self._get_positional_actions()
1967 groups = self._mutually_exclusive_groups
1968 formatter.add_usage(None, positionals, groups, '')
1969 kwargs['prog'] = formatter.format_help().strip()
1970
1971 # create the parsers action and add it to the positionals list
1972 parsers_class = self._pop_action_class(kwargs, 'parsers')
1973 action = parsers_class(option_strings=[], **kwargs)
1974 action._color = self.color
1975 self._check_help(action)
1976 self._subparsers._add_action(action)
1977
1978 # return the created parsers action
1979 return action
1980
1981 def _add_action(self, action):
1982 if action.option_strings:

Calls 13

_set_colorMethod · 0.80
add_usageMethod · 0.80
_pop_action_classMethod · 0.80
_check_helpMethod · 0.80
_Function · 0.50
setdefaultMethod · 0.45
popMethod · 0.45
add_argument_groupMethod · 0.45
getMethod · 0.45
stripMethod · 0.45
format_helpMethod · 0.45