Skip to content

Commit 7a08201

Browse files
committed
Making sure the resolved macro statement contains the originally typed line
1 parent 1bade42 commit 7a08201

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

cmd2/cmd2.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,12 +1854,17 @@ def _complete_statement(self, line: str, used_macros: Optional[List[str]] = None
18541854
backwards compatibility with the standard library version of cmd.
18551855
18561856
:param line: the line being parsed
1857-
:param used_macros: a list of macros that have already been resolved during parsing.
1858-
this should be None for the first call.
1857+
:param used_macros: a list of macros that have already been resolved during parsing of this line.
1858+
this should only be set by _complete_statement when it recursively calls itself to
1859+
resolve macros
18591860
:return: the completed Statement
18601861
"""
1862+
# Check if this is the top-level call
18611863
if used_macros is None:
18621864
used_macros = []
1865+
orig_line = line
1866+
else:
1867+
orig_line = None
18631868

18641869
while True:
18651870
try:
@@ -1911,11 +1916,26 @@ def _complete_statement(self, line: str, used_macros: Optional[List[str]] = None
19111916
line = self._resolve_macro(statement)
19121917
if line is None:
19131918
raise EmptyStatement()
1914-
used_macros.append(statement.command)
19151919

1916-
# Parse the resolved macro
1920+
# Parse the resolved macro line
1921+
used_macros.append(statement.command)
19171922
statement = self._complete_statement(line, used_macros)
19181923

1924+
if orig_line is not None:
1925+
# All macro resolution is finished. Build a Statement that contains the resolved
1926+
# strings but the originally typed line for its raw member.
1927+
statement = Statement(statement.args,
1928+
raw=orig_line,
1929+
command=statement.command,
1930+
arg_list=statement.arg_list,
1931+
multiline_command=statement.multiline_command,
1932+
terminator=statement.terminator,
1933+
suffix=statement.suffix,
1934+
pipe_to=statement.pipe_to,
1935+
output=statement.output,
1936+
output_to=statement.output_to,
1937+
)
1938+
19191939
return statement
19201940

19211941
def _resolve_macro(self, statement: Statement) -> Optional[str]:

0 commit comments

Comments
 (0)