diff options
author | Eric Lin <anselor@gmail.com> | 2018-05-02 14:53:20 -0400 |
---|---|---|
committer | Eric Lin <anselor@gmail.com> | 2018-05-02 14:53:20 -0400 |
commit | a95c8a065abeac286c196783393ecc49e4356f54 (patch) | |
tree | b4575eda772450b54620d16c09d4d29c52abdec7 /cmd2/utils.py | |
parent | d2d3c2f37d5324b5bc967fe268a92f9d563a3a30 (diff) | |
parent | 148f05d0af66f38c8ba6ca3a5619f50a8bb1b8a9 (diff) | |
download | cmd2-git-a95c8a065abeac286c196783393ecc49e4356f54.tar.gz |
Merge branch 'bash_completion' into bash_to_pyscript
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 167879aa..a975c6b8 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -5,6 +5,7 @@ import collections from . import constants + def strip_ansi(text: str) -> str: """Strip ANSI escape codes from a string. @@ -14,6 +15,19 @@ def strip_ansi(text: str) -> str: 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 + + def namedtuple_with_defaults(typename, field_names, default_values=()): """ Convenience function for defining a namedtuple with default values @@ -41,3 +55,4 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): prototype = T(*default_values) T.__new__.__defaults__ = tuple(prototype) return T + |