diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-11-11 21:50:44 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-11-11 21:50:44 -0500 |
commit | f02cf54284c4feacee5647d29665158fa5137f5f (patch) | |
tree | e421ec9b49338a312c0db759d4b5c87c7299e1a7 /cmd2/utils.py | |
parent | 0f11ffa3b992e3f777b96dfe46d4274bfca0dcc8 (diff) | |
parent | d4dc6b6a98fdb44b08701a3826ee88b6c22b72fd (diff) | |
download | cmd2-git-f02cf54284c4feacee5647d29665158fa5137f5f.tar.gz |
Merge branch 'master' into 2.0
# Conflicts:
# CHANGELOG.md
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index cd716083..7c5f1560 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -281,17 +281,29 @@ def natural_sort(list_to_sort: Iterable[str]) -> List[str]: return sorted(list_to_sort, key=natural_keys) -def unquote_specific_tokens(args: List[str], tokens_to_unquote: List[str]) -> None: +def quote_specific_tokens(tokens: List[str], tokens_to_quote: List[str]) -> None: """ - Unquote a specific tokens in a list of command-line arguments - This is used when certain tokens have to be passed to another command - :param args: the command line args - :param tokens_to_unquote: the tokens, which if present in args, to unquote + Quote specific tokens in a list + + :param tokens: token list being edited + :param tokens_to_quote: the tokens, which if present in tokens, to quote + """ + for i, token in enumerate(tokens): + if token in tokens_to_quote: + tokens[i] = quote_string(token) + + +def unquote_specific_tokens(tokens: List[str], tokens_to_unquote: List[str]) -> None: + """ + Unquote specific tokens in a list + + :param tokens: token list being edited + :param tokens_to_unquote: the tokens, which if present in tokens, to unquote """ - for i, arg in enumerate(args): - unquoted_arg = strip_quotes(arg) - if unquoted_arg in tokens_to_unquote: - args[i] = unquoted_arg + for i, token in enumerate(tokens): + unquoted_token = strip_quotes(token) + if unquoted_token in tokens_to_unquote: + tokens[i] = unquoted_token def expand_user(token: str) -> str: |