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)
| 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.""" |
no test coverage detected