diff options
author | kotfu <kotfu@kotfu.net> | 2018-06-19 10:06:20 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-06-19 10:06:20 -0600 |
commit | 101395a437ef66846e207c039a12ee946128fab9 (patch) | |
tree | 4e024a7899396f4e111bda10f2cd8c053db12a5b /cmd2/parsing.py | |
parent | b0a0251c77e73a3f3c0a755f3fabb9fdf136ccfa (diff) | |
parent | b5def934f4d368a7e1a1fe67a98b3cdcc14cd2d9 (diff) | |
download | cmd2-git-101395a437ef66846e207c039a12ee946128fab9.tar.gz |
Merge branch 'master' into plugin_functions
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 1db78526..b220f1c4 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- """Statement parsing classes for cmd2""" +import os import re import shlex from typing import List, Tuple, Dict @@ -42,7 +43,7 @@ class Statement(str): from the elements of the list, and aliases and shortcuts are expanded :type argv: list - :var terminator: the charater which terminated the multiline command, if + :var terminator: the character which terminated the multiline command, if there was one :type terminator: str or None :var suffix: characters appearing after the terminator but before output @@ -53,7 +54,7 @@ class Statement(str): :type pipe_to: list :var output: if output was redirected, the redirection token, i.e. '>>' :type output: str or None - :var output_to: if output was redirected, the destination, usually a filename + :var output_to: if output was redirected, the destination file :type output_to: str or None """ @@ -329,6 +330,11 @@ class StatementParser: pipe_pos = tokens.index(constants.REDIRECTION_PIPE) # save everything after the first pipe as tokens pipe_to = tokens[pipe_pos+1:] + + for pos, cur_token in enumerate(pipe_to): + unquoted_token = utils.strip_quotes(cur_token) + pipe_to[pos] = os.path.expanduser(unquoted_token) + # remove all the tokens after the pipe tokens = tokens[:pipe_pos] except ValueError: @@ -341,7 +347,12 @@ class StatementParser: try: output_pos = tokens.index(constants.REDIRECTION_OUTPUT) output = constants.REDIRECTION_OUTPUT - output_to = ' '.join(tokens[output_pos+1:]) + + # Check if we are redirecting to a file + if len(tokens) > output_pos + 1: + unquoted_path = utils.strip_quotes(tokens[output_pos + 1]) + output_to = os.path.expanduser(unquoted_path) + # remove all the tokens after the output redirect tokens = tokens[:output_pos] except ValueError: @@ -350,7 +361,12 @@ class StatementParser: try: output_pos = tokens.index(constants.REDIRECTION_APPEND) output = constants.REDIRECTION_APPEND - output_to = ' '.join(tokens[output_pos+1:]) + + # Check if we are redirecting to a file + if len(tokens) > output_pos + 1: + unquoted_path = utils.strip_quotes(tokens[output_pos + 1]) + output_to = os.path.expanduser(unquoted_path) + # remove all tokens after the output redirect tokens = tokens[:output_pos] except ValueError: |