diff options
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-x | cmd2/cmd2.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8d8a5b07..184da5a9 100755 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -49,6 +49,8 @@ from code import InteractiveConsole import pyparsing import pyperclip +import cmd2.constants as constants + # Set up readline from .rl_utils import rl_force_redisplay, readline, rl_type, RlType from .argparse_completer import AutoCompleter, ACArgumentParser @@ -134,10 +136,6 @@ POSIX_SHLEX = False # Strip outer quotes for convenience if POSIX_SHLEX = False STRIP_QUOTES_FOR_NON_POSIX = True -# Used for tab completion and word breaks. Do not change. -QUOTES = ['"', "'"] -REDIRECTION_CHARS = ['|', '<', '>'] - # optional attribute, when tagged on a function, allows cmd2 to categorize commands HELP_CATEGORY = 'help_category' HELP_SUMMARY = 'help_summary' @@ -1021,7 +1019,7 @@ class Cmd(cmd.Cmd): Both items are None """ unclosed_quote = '' - quotes_to_try = copy.copy(QUOTES) + quotes_to_try = copy.copy(constants.QUOTES) tmp_line = line[:endidx] tmp_endidx = endidx @@ -1064,7 +1062,7 @@ class Cmd(cmd.Cmd): for cur_initial_token in initial_tokens: # Save tokens up to 1 character in length or quoted tokens. No need to parse these. - if len(cur_initial_token) <= 1 or cur_initial_token[0] in QUOTES: + if len(cur_initial_token) <= 1 or cur_initial_token[0] in constants.QUOTES: raw_tokens.append(cur_initial_token) continue @@ -1076,10 +1074,10 @@ class Cmd(cmd.Cmd): cur_raw_token = '' while True: - if cur_char not in REDIRECTION_CHARS: + if cur_char not in constants.REDIRECTION_CHARS: # Keep appending to cur_raw_token until we hit a redirect char - while cur_char not in REDIRECTION_CHARS: + while cur_char not in constants.REDIRECTION_CHARS: cur_raw_token += cur_char cur_index += 1 if cur_index < len(cur_initial_token): @@ -1485,7 +1483,7 @@ class Cmd(cmd.Cmd): if len(raw_tokens) > 1: # Build a list of all redirection tokens - all_redirects = REDIRECTION_CHARS + ['>>'] + all_redirects = constants.REDIRECTION_CHARS + ['>>'] # Check if there are redirection strings prior to the token being completed seen_pipe = False @@ -1695,7 +1693,7 @@ class Cmd(cmd.Cmd): raw_completion_token = raw_tokens[-1] # Check if the token being completed has an opening quote - if raw_completion_token and raw_completion_token[0] in QUOTES: + if raw_completion_token and raw_completion_token[0] in constants.QUOTES: # Since the token is still being completed, we know the opening quote is unclosed unclosed_quote = raw_completion_token[0] @@ -2391,11 +2389,11 @@ class Cmd(cmd.Cmd): readline.set_completer(self.complete) # Break words on whitespace and quotes when tab completing - completer_delims = " \t\n" + ''.join(QUOTES) + completer_delims = " \t\n" + ''.join(constants.QUOTES) if self.allow_redirection: # If redirection is allowed, then break words on those characters too - completer_delims += ''.join(REDIRECTION_CHARS) + completer_delims += ''.join(constants.REDIRECTION_CHARS) readline.set_completer_delims(completer_delims) @@ -2840,13 +2838,13 @@ Usage: Usage: unalias [-a] name [name ...] # Check if the token is quoted. Since shlex.split() passed, there isn't # an unclosed quote, so we only need to check the first character. first_char = tokens[index][0] - if first_char in QUOTES: + if first_char in constants.QUOTES: tokens[index] = strip_quotes(tokens[index]) tokens[index] = os.path.expanduser(tokens[index]) # Restore the quotes - if first_char in QUOTES: + if first_char in constants.QUOTES: tokens[index] = first_char + tokens[index] + first_char expanded_command = ' '.join(tokens) |