summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-04-27 22:57:47 -0400
committerEric Lin <anselor@gmail.com>2018-04-27 22:57:47 -0400
commit452c396c1b3b417a1e085d5b4ab192bbc13d34b8 (patch)
treec1dce51fc4253a664c474bcff6e9b3801f1cf977 /cmd2/utils.py
parentae86103f6b8acf7765804382237564356f095b74 (diff)
parent1306eebade58d7ffe5d0ab4008006b7fb3501b54 (diff)
downloadcmd2-git-452c396c1b3b417a1e085d5b4ab192bbc13d34b8.tar.gz
Merge remote-tracking branch 'origin/master' into bash_completion
Updated argcomplete_bridge to use new constants/utils.
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
new file mode 100644
index 00000000..9705e4f7
--- /dev/null
+++ b/cmd2/utils.py
@@ -0,0 +1,27 @@
+#
+# coding=utf-8
+"""Shared utility functions"""
+
+from . import constants
+
+
+def strip_ansi(text: str) -> str:
+ """Strip ANSI escape codes from a string.
+
+ :param text: string which may contain ANSI escape codes
+ :return: the same string with any ANSI escape codes removed
+ """
+ return constants.ANSI_ESCAPE_RE.sub('', text)
+
+
+def strip_quotes(arg: str) -> str:
+ """ Strip outer quotes from a string.
+
+ Applies to both single and double quotes.
+
+ :param arg: string to strip outer quotes from
+ :return: same string with potentially outer quotes stripped
+ """
+ if len(arg) > 1 and arg[0] == arg[-1] and arg[0] in constants.QUOTES:
+ arg = arg[1:-1]
+ return arg