Skip to content

Commit 4902d1c

Browse files
committed
Changed default() to print the actual command run for unknown syntax errors.
Fixed default() to run the resolved command instead of raw when default_to_shell is True.
1 parent d9f5f2b commit 4902d1c

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

cmd2/cmd2.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,15 +2060,14 @@ def default(self, statement: Statement) -> None:
20602060
20612061
:param statement: Statement object with parsed input
20622062
"""
2063-
arg = statement.raw
20642063
if self.default_to_shell:
2065-
result = os.system(arg)
2064+
result = os.system(statement.command_and_args)
20662065
# If os.system() succeeded, then don't print warning about unknown command
20672066
if not result:
20682067
return
20692068

20702069
# Print out a message stating this is an unknown command
2071-
self.poutput('*** Unknown syntax: {}\n'.format(arg))
2070+
self.poutput('*** Unknown syntax: {}\n'.format(statement.command_and_args))
20722071

20732072
def pseudo_raw_input(self, prompt: str) -> str:
20742073
"""Began life as a copy of cmd's cmdloop; like raw_input but
@@ -2946,16 +2945,11 @@ def _reset_py_display() -> None:
29462945

29472946
py_description = ("Invoke Python command or shell\n"
29482947
"\n"
2949-
"When invoking a command directly from the command line, note this shell has\n"
2950-
"limited ability to parse Python statements into tokens. If an opening quote is\n"
2951-
"not preceded by whitespace, its closing quote should appear before any\n"
2952-
"whitespace. Otherwise whitespace in the parsed tokens will get lost.\n"
2948+
"Note that, when invoking a command directly from the command line, this shell\n"
2949+
"has limited ability to parse Python statements into tokens. In particular,\n"
2950+
"there may be problems with whitespace and quotes depending on their placement.\n"
29532951
"\n"
2954-
"Note the opening quote before 'This' in the following commands\n"
2955-
'py print("This " + "is bad")\n'
2956-
'py print("This" + " is good")\n'
2957-
"\n"
2958-
"If you see strange parsing behavior, its best to just open the Python shell by\n"
2952+
"If you see strange parsing behavior, it's best to just open the Python shell by\n"
29592953
"providing no arguments to py and run more complex statements there.")
29602954

29612955
py_parser = ACArgumentParser(description=py_description)

0 commit comments

Comments
 (0)