summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py17
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.