diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 13:58:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 13:58:42 -0400 |
commit | b823665299593fa2f12a5f1a86af11dbb6b7bc4b (patch) | |
tree | b59fc95248a707e0c3ef69874cfccf24c9c5b392 /cmd2/utils.py | |
parent | 346589e7e81adcd2aff883776249778d57eb4faf (diff) | |
parent | 29eeef6829fc7fc4a7e706d90871e8c347de773a (diff) | |
download | cmd2-git-b823665299593fa2f12a5f1a86af11dbb6b7bc4b.tar.gz |
Merge pull request #739 from python-cmd2/presentation_stuff
Presentation stuff
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index b19c2b49..d0ce10bc 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -25,11 +25,8 @@ def is_quoted(arg: str) -> bool: return len(arg) > 1 and arg[0] == arg[-1] and arg[0] in constants.QUOTES -def quote_string_if_needed(arg: str) -> str: - """ Quotes a string if it contains spaces and isn't already quoted """ - if is_quoted(arg) or ' ' not in arg: - return arg - +def quote_string(arg: str) -> str: + """Quote a string""" if '"' in arg: quote = "'" else: @@ -38,8 +35,16 @@ def quote_string_if_needed(arg: str) -> str: return quote + arg + quote +def quote_string_if_needed(arg: str) -> str: + """Quote a string if it contains spaces and isn't already quoted""" + if is_quoted(arg) or ' ' not in arg: + return arg + + return quote_string(arg) + + def strip_quotes(arg: str) -> str: - """ Strip outer quotes from a string. + """Strip outer quotes from a string. Applies to both single and double quotes. |