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

Class Statement

cmd2/parsing.py:102–244  ·  view source on GitHub ↗

String subclass with additional attributes to store the results of parsing. Instances of this class should not be created by anything other than the [StatementParser.parse][cmd2.parsing.StatementParser.parse] method, nor should any of the attributes be modified once the object is create

Source from the content-addressed store, hash-verified

100
101@dataclass(frozen=True)
102class Statement(str): # noqa: SLOT000
103 """String subclass with additional attributes to store the results of parsing.
104
105 Instances of this class should not be created by anything other than the
106 [StatementParser.parse][cmd2.parsing.StatementParser.parse] method, nor should any of the
107 attributes be modified once the object is created.
108
109 The string portion of the class contains the arguments, but not the
110 command, nor the output redirection clauses.
111
112 Tips:
113
114 1. `argparse <https://docs.python.org/3/library/argparse.html>`_ is your
115 friend for anything complex. ``cmd2`` has the decorator
116 ([cmd2.decorators.with_argparser][]) which you can
117 use to make your command method receive a namespace of parsed arguments,
118 whether positional or denoted with switches.
119
120 2. For commands with simple positional arguments, use
121 [args][cmd2.parsing.Statement.args] or [arg_list][cmd2.parsing.Statement.arg_list]
122
123 3. If you don&#x27;t want to have to worry about quoted arguments, see
124 [argv][cmd2.parsing.Statement.argv] for a trick which strips quotes off for you.
125 """
126
127 # A space-delimited string containing the arguments to the command (quotes preserved).
128 # This does not include any output redirection clauses.
129 # Note: If a terminator is present, characters that would otherwise be
130 # redirectors (like '>') are treated as literal arguments if they appear
131 # before the terminator.
132 args: str = ""
133
134 # The original, unmodified input string
135 raw: str = ""
136
137 # The resolved command name (after shortcut/alias expansion)
138 command: str = ""
139
140 # Whether the command is recognized as a multiline-capable command
141 multiline_command: bool = False
142
143 # The character which terminates the command/arguments portion of the input.
144 # While primarily used to signal the end of multiline commands, its presence
145 # defines the boundary between arguments and any subsequent redirection.
146 terminator: str = ""
147
148 # Characters appearing after the terminator but before output redirection
149 suffix: str = ""
150
151 # The operator used to redirect output (e.g. '>', '>>', or '|').
152 redirector: str = ""
153
154 # The destination for the redirected output (a file path or a shell command).
155 # Quotes are preserved.
156 redirect_to: str = ""
157
158 def __new__(cls, value: object, *_pos_args: Any, **_kw_args: Any) -> Self:
159 """Create a new instance of Statement.

Callers 6

histFunction · 0.90
persisted_histFunction · 0.90
histitemFunction · 0.90
parseMethod · 0.85
precmdMethod · 0.85

Calls

no outgoing calls

Tested by 4

histFunction · 0.72
persisted_histFunction · 0.72
histitemFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…