Skip to content

Commit 5e6cf76

Browse files
committed
Quoting strings with utility function
1 parent d0654e1 commit 5e6cf76

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cmd2/pyscript_bridge.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import List, Callable, Optional
1414

1515
from .argparse_completer import _RangeAction
16-
from .utils import namedtuple_with_defaults, StdSim
16+
from .utils import namedtuple_with_defaults, StdSim, quote_string_if_needed
1717

1818
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
1919
if sys.version_info < (3, 5):
@@ -225,8 +225,7 @@ def process_flag(action, value):
225225
if isinstance(value, List) or isinstance(value, tuple):
226226
for item in value:
227227
item = str(item).strip()
228-
if ' ' in item:
229-
item = '"{}"'.format(item)
228+
item = quote_string_if_needed(item)
230229
cmd_str[0] += '{} '.format(item)
231230

232231
# If this is a flag parameter that can accept a variable number of arguments and we have not
@@ -238,8 +237,7 @@ def process_flag(action, value):
238237

239238
else:
240239
value = str(value).strip()
241-
if ' ' in value:
242-
value = '"{}"'.format(value)
240+
value = quote_string_if_needed(value)
243241
cmd_str[0] += '{} '.format(value)
244242

245243
# If this is a flag parameter that can accept a variable number of arguments and we have not

0 commit comments

Comments
 (0)