Skip to content

Commit 802000b

Browse files
committed
Ensure args is ‘’ for backwards compatibility with cmd
1 parent dbf4846 commit 802000b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cmd2/parsing.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Statement(str):
3232
:var args: the arguments to the command, not including any output
3333
redirection or terminators. quoted arguments remain
3434
quoted.
35-
:type args: str
35+
:type args: str or None
3636
:var terminator: the charater which terminated the multiline command, if
3737
there was one
3838
:type terminator: str or None
@@ -52,8 +52,7 @@ def __init__(self, obj):
5252
self.raw = str(obj)
5353
self.command = None
5454
self.multiline_command = None
55-
# has to be an empty string for compatibility with standard library cmd
56-
self.args = ''
55+
self.args = None
5756
self.terminator = None
5857
self.suffix = None
5958
self.pipe_to = None
@@ -175,7 +174,7 @@ def parse(self, rawinput: str) -> Statement:
175174
terminator = LINE_FEED
176175

177176
command = None
178-
args = ''
177+
args = None
179178

180179
# lex the input into a list of tokens
181180
tokens = self.tokenize(rawinput)
@@ -263,9 +262,13 @@ def parse(self, rawinput: str) -> Statement:
263262
multiline_command = None
264263

265264
# build the statement
266-
statement = Statement(args)
265+
# string representation of args must be an empty string instead of
266+
# None for compatibility with standard library cmd
267+
statement = Statement('' if args is None else args)
267268
statement.raw = rawinput
268269
statement.command = command
270+
# if there are no args we will use None since we don't have to worry
271+
# about compatibility wiht standard library cmd
269272
statement.args = args
270273
statement.terminator = terminator
271274
statement.output = output
@@ -331,8 +334,11 @@ def _expand(self, line: str) -> str:
331334

332335
@staticmethod
333336
def _command_and_args(tokens: List[str]) -> Tuple[str, str]:
334-
"""given a list of tokens, and return a tuple of the command
337+
"""Given a list of tokens, return a tuple of the command
335338
and the args as a string.
339+
340+
The args string will be '' instead of None to retain backwards compatibility
341+
with cmd in the standard library.
336342
"""
337343
command = None
338344
args = ''

0 commit comments

Comments
 (0)