summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-05-02 11:34:16 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-05-02 11:34:16 -0400
commit7a08201916b5862e8e51d3398a9fec1e5dff354f (patch)
treea46b01d659a5fa62eba3bff82c45b0e3e6fc4795 /cmd2/cmd2.py
parent1bade4202d9a8df2be9561bc8d3a9cb26fefd7b0 (diff)
downloadcmd2-git-7a08201916b5862e8e51d3398a9fec1e5dff354f.tar.gz
Making sure the resolved macro statement contains the originally typed line
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 1557592b..e19bb84c 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1854,12 +1854,17 @@ class Cmd(cmd.Cmd):
backwards compatibility with the standard library version of cmd.
:param line: the line being parsed
- :param used_macros: a list of macros that have already been resolved during parsing.
- this should be None for the first call.
+ :param used_macros: a list of macros that have already been resolved during parsing of this line.
+ this should only be set by _complete_statement when it recursively calls itself to
+ resolve macros
:return: the completed Statement
"""
+ # Check if this is the top-level call
if used_macros is None:
used_macros = []
+ orig_line = line
+ else:
+ orig_line = None
while True:
try:
@@ -1911,11 +1916,26 @@ class Cmd(cmd.Cmd):
line = self._resolve_macro(statement)
if line is None:
raise EmptyStatement()
- used_macros.append(statement.command)
- # Parse the resolved macro
+ # Parse the resolved macro line
+ used_macros.append(statement.command)
statement = self._complete_statement(line, used_macros)
+ if orig_line is not None:
+ # All macro resolution is finished. Build a Statement that contains the resolved
+ # strings but the originally typed line for its raw member.
+ statement = Statement(statement.args,
+ raw=orig_line,
+ command=statement.command,
+ arg_list=statement.arg_list,
+ multiline_command=statement.multiline_command,
+ terminator=statement.terminator,
+ suffix=statement.suffix,
+ pipe_to=statement.pipe_to,
+ output=statement.output,
+ output_to=statement.output_to,
+ )
+
return statement
def _resolve_macro(self, statement: Statement) -> Optional[str]: