diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-13 12:52:49 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-13 12:52:49 -0400 |
commit | c4ee21446e1507ebd5c42a521fa2c0bcb2648c85 (patch) | |
tree | 8d209fc86254c727c9cdd502d58d9e0ec2331cd9 /cmd2/parsing.py | |
parent | 8ad8ddd10bf35f38e22b2c8f381faa4b2f87c853 (diff) | |
download | cmd2-git-c4ee21446e1507ebd5c42a521fa2c0bcb2648c85.tar.gz |
Preserving originally typed quotes of Statement.output_to for use in Statement.post_command()
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 067c9bf4..8febd270 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- """Statement parsing classes for cmd2""" -import os import re import shlex from typing import Dict, Iterable, List, Optional, Tuple, Union @@ -166,7 +165,7 @@ class Statement(str): # if output was redirected, the redirection token, i.e. '>>' output = attr.ib(default='', validator=attr.validators.instance_of(str)) - # if output was redirected, the destination file + # if output was redirected, the destination file token (quotes preserved) output_to = attr.ib(default='', validator=attr.validators.instance_of(str)) def __new__(cls, value: object, *pos_args, **kw_args): @@ -213,7 +212,7 @@ class Statement(str): if self.output: rtn += ' ' + self.output if self.output_to: - rtn += ' ' + utils.quote_string_if_needed(self.output_to) + rtn += ' ' + self.output_to return rtn @@ -495,9 +494,11 @@ class StatementParser: output = constants.REDIRECTION_APPEND output_index = append_index + # Check if we are redirecting to a file if len(tokens) > output_index + 1: unquoted_path = utils.strip_quotes(tokens[output_index + 1]) - output_to = os.path.expanduser(unquoted_path) + if unquoted_path: + output_to = utils.expand_user(tokens[output_index + 1]) # remove all the tokens after the output redirect tokens = tokens[:output_index] |