Skip to content

Commit 87fe6ba

Browse files
committed
Simplified recreation of resolved-macro Statement.
1 parent 78e239e commit 87fe6ba

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

cmd2/cmd2.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,20 +2921,14 @@ def _input_line_to_statement(self, line: str) -> Statement:
29212921
else:
29222922
break
29232923

2924-
# This will be true when a macro was used
2924+
# If a macro was expanded, the 'statement' now contains the expanded text.
2925+
# We need to swap the 'raw' attribute back to the string the user typed
2926+
# so history shows the original line.
29252927
if orig_line != statement.raw:
2926-
# Build a Statement that contains the resolved macro line
2927-
# but the originally typed line for its raw member.
2928-
statement = Statement(
2929-
statement.args,
2930-
raw=orig_line,
2931-
command=statement.command,
2932-
multiline_command=statement.multiline_command,
2933-
terminator=statement.terminator,
2934-
suffix=statement.suffix,
2935-
redirector=statement.redirector,
2936-
redirect_to=statement.redirect_to,
2937-
)
2928+
statement_dict = statement.to_dict()
2929+
statement_dict["raw"] = orig_line
2930+
statement = Statement.from_dict(statement_dict)
2931+
29382932
return statement
29392933

29402934
def _resolve_macro(self, statement: Statement) -> str | None:

0 commit comments

Comments
 (0)