Inspect the positional arguments until the cmd2.Cmd argument is found. Assumes that we will find cmd2.Cmd followed by the command statement object or string. :arg args: The positional arguments to inspect :return: The cmd2.Cmd reference and the command line statement.
(args: tuple[Any, ...])
| 72 | # found we can swap out the statement with each decorator's specific parameters |
| 73 | ########################## |
| 74 | def _parse_positionals(args: tuple[Any, ...]) -> tuple["Cmd", Statement | str]: |
| 75 | """Inspect the positional arguments until the cmd2.Cmd argument is found. |
| 76 | |
| 77 | Assumes that we will find cmd2.Cmd followed by the command statement object or string. |
| 78 | |
| 79 | :arg args: The positional arguments to inspect |
| 80 | :return: The cmd2.Cmd reference and the command line statement. |
| 81 | """ |
| 82 | for pos, arg in enumerate(args): |
| 83 | from .cmd2 import Cmd |
| 84 | |
| 85 | if isinstance(arg, (Cmd, CommandSet)) and len(args) > pos + 1: |
| 86 | if isinstance(arg, CommandSet): |
| 87 | arg = arg._cmd # noqa: PLW2901 |
| 88 | next_arg = args[pos + 1] |
| 89 | if isinstance(next_arg, (Statement, str)): |
| 90 | return arg, args[pos + 1] |
| 91 | |
| 92 | # This shouldn't happen unless we forget to pass statement in `Cmd.onecmd` or |
| 93 | # somehow call the unbound class method. |
| 94 | raise TypeError("Expected arguments: cmd: cmd2.Cmd, statement: Union[Statement, str] Not found") |
| 95 | |
| 96 | |
| 97 | def _arg_swap(args: Sequence[Any], search_arg: Any, *replace_arg: Any) -> list[Any]: |
no outgoing calls
no test coverage detected
searching dependent graphs…