Supports cmd2's help command in the completion of subcommand names. :param text: the string prefix we are attempting to match (all matches must begin with it) :param line: the current input line with leading whitespace removed :param begidx: the beginning index of the prefix
(self, text: str, line: str, begidx: int, endidx: int, tokens: Sequence[str])
| 653 | ) |
| 654 | |
| 655 | def complete_subcommand_help(self, text: str, line: str, begidx: int, endidx: int, tokens: Sequence[str]) -> Completions: |
| 656 | """Supports cmd2's help command in the completion of subcommand names. |
| 657 | |
| 658 | :param text: the string prefix we are attempting to match (all matches must begin with it) |
| 659 | :param line: the current input line with leading whitespace removed |
| 660 | :param begidx: the beginning index of the prefix text |
| 661 | :param endidx: the ending index of the prefix text |
| 662 | :param tokens: arguments passed to command/subcommand |
| 663 | :return: a Completions object |
| 664 | """ |
| 665 | # If our parser has subcommands, we must examine the tokens and check if they are subcommands |
| 666 | # If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter. |
| 667 | if self._subcommand_action is not None: |
| 668 | for token_index, token in enumerate(tokens): |
| 669 | if token in self._subcommand_action.choices: |
| 670 | parser = self._subcommand_action.choices[token] |
| 671 | completer_type = self._cmd2_app._determine_ap_completer_type(parser) |
| 672 | completer = completer_type(parser, self._cmd2_app) |
| 673 | return completer.complete_subcommand_help(text, line, begidx, endidx, tokens[token_index + 1 :]) |
| 674 | |
| 675 | if token_index == len(tokens) - 1: |
| 676 | # Since this is the last token, we will attempt to complete it |
| 677 | return self._cmd2_app.basic_complete(text, line, begidx, endidx, self._subcommand_action.choices) |
| 678 | break |
| 679 | return Completions() |
| 680 | |
| 681 | def print_help(self, tokens: Sequence[str], file: IO[str] | None = None) -> None: |
| 682 | """Supports cmd2's help command in the printing of help text. |