MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / get

Method get

cmd2/cmd2.py:266–297  ·  view source on GitHub ↗

Return a given method's parser or None if the method is not argparse-based. If the parser does not yet exist, it will be created.

(self, command_method: BoundCommandFunc)

Source from the content-addressed store, hash-verified

264 return bool(parser)
265
266 def get(self, command_method: BoundCommandFunc) -> Cmd2ArgumentParser | None:
267 """Return a given method's parser or None if the method is not argparse-based.
268
269 If the parser does not yet exist, it will be created.
270 """
271 full_method_name = self._fully_qualified_name(command_method)
272 if not full_method_name:
273 return None
274
275 if full_method_name not in self._parsers:
276 if not command_method.__name__.startswith(COMMAND_FUNC_PREFIX):
277 return None
278 command = command_method.__name__[len(COMMAND_FUNC_PREFIX) :]
279
280 parser_builder = getattr(command_method, constants.CMD_ATTR_ARGPARSER, None)
281 if parser_builder is None:
282 return None
283
284 parent = self._cmd.find_commandset_for_command(command) or self._cmd
285 parser = self._cmd._build_parser(parent, parser_builder)
286
287 # To ensure accurate usage strings, recursively update 'prog' values
288 # within the parser to match the command name.
289 parser.update_prog(command)
290
291 # If the description has not been set, then use the method docstring if one exists
292 if parser.description is None and command_method.__doc__:
293 parser.description = strip_doc_annotations(command_method.__doc__)
294
295 self._parsers[full_method_name] = parser
296
297 return self._parsers.get(full_method_name)
298
299 def remove(self, command_method: BoundCommandFunc) -> None:
300 """Remove a given method's parser if it exists."""

Callers 13

__contains__Method · 0.95
_check_uninstallableMethod · 0.45
format_exceptionMethod · 0.45
ppagedMethod · 0.45
_perform_completionMethod · 0.45
completeMethod · 0.45
_redirect_outputMethod · 0.45
do_helpMethod · 0.45
do_shellMethod · 0.45

Calls 5

_fully_qualified_nameMethod · 0.95
strip_doc_annotationsFunction · 0.85
_build_parserMethod · 0.80
update_progMethod · 0.80

Tested by

no test coverage detected