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

Method get_command_arg_list

cmd2/parsing.py:616–646  ·  view source on GitHub ↗

Retrieve just the arguments being passed to their ``do_*`` methods as a list. Convenience method used by the argument parsing decorators. :param command_name: name of the command being run :param to_parse: what is being passed to the ``do_*`` method. It can be one of two ty

(
        self, command_name: str, to_parse: Statement | str, preserve_quotes: bool
    )

Source from the content-addressed store, hash-verified

614 )
615
616 def get_command_arg_list(
617 self, command_name: str, to_parse: Statement | str, preserve_quotes: bool
618 ) -> tuple[Statement, list[str]]:
619 """Retrieve just the arguments being passed to their ``do_*`` methods as a list.
620
621 Convenience method used by the argument parsing decorators.
622
623 :param command_name: name of the command being run
624 :param to_parse: what is being passed to the ``do_*`` method. It can be one of two types:
625
626 1. An already parsed [cmd2.Statement][]
627 2. An argument string in cases where a ``do_*`` method is
628 explicitly called. Calling ``do_help('alias create')`` would
629 cause ``to_parse`` to be 'alias create'.
630
631 In this case, the string will be converted to a
632 [cmd2.Statement][] and returned along with
633 the argument list.
634
635 :param preserve_quotes: if ``True``, then quotes will not be stripped from
636 the arguments
637 :return: A tuple containing the [cmd2.Statement][] and a list of
638 strings representing the arguments
639 """
640 # Check if to_parse needs to be converted to a Statement
641 if not isinstance(to_parse, Statement):
642 to_parse = self.parse(command_name + " " + to_parse)
643
644 if preserve_quotes:
645 return to_parse, to_parse.arg_list
646 return to_parse, to_parse.argv[1:]
647
648 def _expand(self, line: str) -> str:
649 """Expand aliases and shortcuts."""

Callers 1

cmd_wrapperFunction · 0.80

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected