Skip to content

Commit ceb3ef5

Browse files
committed
Get rid of last hard-coded redirection constants
1 parent ce5092f commit ceb3ef5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

cmd2/cmd2.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,29 +1148,26 @@ def _redirect_complete(self, text, line, begidx, endidx, compfunc):
11481148

11491149
if len(raw_tokens) > 1:
11501150

1151-
# Build a list of all redirection tokens
1152-
all_redirects = constants.REDIRECTION_CHARS + ['>>']
1153-
11541151
# Check if there are redirection strings prior to the token being completed
11551152
seen_pipe = False
11561153
has_redirection = False
11571154

11581155
for cur_token in raw_tokens[:-1]:
1159-
if cur_token in all_redirects:
1156+
if cur_token in constants.REDIRECTION_TOKENS:
11601157
has_redirection = True
11611158

1162-
if cur_token == '|':
1159+
if cur_token == constants.REDIRECTION_PIPE:
11631160
seen_pipe = True
11641161

11651162
# Get token prior to the one being completed
11661163
prior_token = raw_tokens[-2]
11671164

11681165
# If a pipe is right before the token being completed, complete a shell command as the piped process
1169-
if prior_token == '|':
1166+
if prior_token == constants.REDIRECTION_PIPE:
11701167
return self.shell_cmd_complete(text, line, begidx, endidx)
11711168

11721169
# Otherwise do path completion either as files to redirectors or arguments to the piped process
1173-
elif prior_token in all_redirects or seen_pipe:
1170+
elif prior_token in constants.REDIRECTION_TOKENS or seen_pipe:
11741171
return self.path_complete(text, line, begidx, endidx)
11751172

11761173
# If there were redirection strings anywhere on the command line, then we

cmd2/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
REDIRECTION_OUTPUT = '>'
1212
REDIRECTION_APPEND = '>>'
1313
REDIRECTION_CHARS = [REDIRECTION_PIPE, REDIRECTION_OUTPUT]
14+
REDIRECTION_TOKENS = [REDIRECTION_PIPE, REDIRECTION_OUTPUT, REDIRECTION_APPEND]
1415

1516
# Regular expression to match ANSI escape codes
1617
ANSI_ESCAPE_RE = re.compile(r'\x1b[^m]*m')

0 commit comments

Comments
 (0)