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

Function _parse_positionals

cmd2/decorators.py:74–94  ·  view source on GitHub ↗

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, ...])

Source from the content-addressed store, hash-verified

72# found we can swap out the statement with each decorator's specific parameters
73##########################
74def _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
97def _arg_swap(args: Sequence[Any], search_arg: Any, *replace_arg: Any) -> list[Any]:

Callers 1

cmd_wrapperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…