diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-07 23:39:08 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-07 23:39:08 -0400 |
commit | cedc154489a654dc229eed3b4494f5eae43a4290 (patch) | |
tree | 5a5300c54a47326f2f293b4486e913fdad7c6cab /cmd2/utils.py | |
parent | f9ea58edbbe27ba5bcea2534263c992e8a2c7ab8 (diff) | |
download | cmd2-git-cedc154489a654dc229eed3b4494f5eae43a4290.tar.gz |
Added capability to redirect pipe commands and chain them together
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index e8e8a611..45e55c2b 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -275,6 +275,27 @@ def unquote_specific_tokens(args: List[str], tokens_to_unquote: List[str]) -> No args[i] = unquoted_arg +def expand_user_in_tokens(tokens: List[str]) -> None: + """ + Call os.path.expanduser() on all tokens in an already parsed list of command-line arguments. + This also supports expanding user in quoted tokens. + :param tokens: tokens to expand + """ + for index, _ in enumerate(tokens): + if tokens[index]: + # Check if the token is quoted. Since parsing already passed, there isn't + # an unclosed quote. So we only need to check the first character. + first_char = tokens[index][0] + if first_char in constants.QUOTES: + tokens[index] = strip_quotes(tokens[index]) + + tokens[index] = os.path.expanduser(tokens[index]) + + # Restore the quotes + if first_char in constants.QUOTES: + tokens[index] = first_char + tokens[index] + first_char + + def find_editor() -> str: """Find a reasonable editor to use by default for the system that the cmd2 application is running on.""" editor = os.environ.get('EDITOR') |