diff options
author | kotfu <kotfu@kotfu.net> | 2018-05-02 09:14:49 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-05-02 09:14:49 -0600 |
commit | 802000bc56ba41955cdd6ffa9043cdc715e023d6 (patch) | |
tree | fc73bd5c8121279310d9a94f7fbe24b2af94a0d0 | |
parent | dbf4846e8bc0e6ca38c928d8fe4752f9b6173803 (diff) | |
download | cmd2-git-802000bc56ba41955cdd6ffa9043cdc715e023d6.tar.gz |
Ensure args is ‘’ for backwards compatibility with cmd
-rw-r--r-- | cmd2/parsing.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 7046b674..2af8ff01 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -32,7 +32,7 @@ class Statement(str): :var args: the arguments to the command, not including any output redirection or terminators. quoted arguments remain quoted. - :type args: str + :type args: str or None :var terminator: the charater which terminated the multiline command, if there was one :type terminator: str or None @@ -52,8 +52,7 @@ class Statement(str): self.raw = str(obj) self.command = None self.multiline_command = None - # has to be an empty string for compatibility with standard library cmd - self.args = '' + self.args = None self.terminator = None self.suffix = None self.pipe_to = None @@ -175,7 +174,7 @@ class StatementParser(): terminator = LINE_FEED command = None - args = '' + args = None # lex the input into a list of tokens tokens = self.tokenize(rawinput) @@ -263,9 +262,13 @@ class StatementParser(): multiline_command = None # build the statement - statement = Statement(args) + # string representation of args must be an empty string instead of + # None for compatibility with standard library cmd + statement = Statement('' if args is None else args) statement.raw = rawinput statement.command = command + # if there are no args we will use None since we don't have to worry + # about compatibility wiht standard library cmd statement.args = args statement.terminator = terminator statement.output = output @@ -331,8 +334,11 @@ class StatementParser(): @staticmethod def _command_and_args(tokens: List[str]) -> Tuple[str, str]: - """given a list of tokens, and return a tuple of the command + """Given a list of tokens, return a tuple of the command and the args as a string. + + The args string will be '' instead of None to retain backwards compatibility + with cmd in the standard library. """ command = None args = '' |