Skip to content

Commit 39ba777

Browse files
Add completion for .commands
1 parent e7a3c20 commit 39ba777

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/sqlite3/_completer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
except ImportError:
66
SQLITE_KEYWORDS = ()
77

8+
SQLITE_KEYWORDS += ('.quit', '.help', '.version')
9+
810
_completion_matches = []
911

1012

1113
def _complete(text, state):
1214
global _completion_matches
1315

1416
if state == 0:
15-
text_upper = text.upper()
16-
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
17+
if text.startswith('.'):
18+
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text)]
19+
else:
20+
text_upper = text.upper()
21+
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
1722
try:
1823
return _completion_matches[state] + " "
1924
except IndexError:

Lib/test/test_sqlite3/test_cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ def test_complete_sql_keywords(self):
249249
self.assertIn(b"SELECT", output)
250250
self.assertIn(b"(1,)", output)
251251

252+
# .commands are completed without changing case
253+
input_ = b".ver\t\n.quit\n"
254+
output = self.write_input(input_)
255+
self.assertIn(b".version", output)
256+
252257
@unittest.skipIf(sys.platform.startswith("freebsd"),
253258
"Two actual tabs are inserted when there are no matching"
254259
" completions in the pseudo-terminal opened by run_pty()"
@@ -301,7 +306,7 @@ def test_complete_no_input(self):
301306
self.assertEqual(len(indices), 2)
302307
start, end = indices
303308
candidates = [l.strip() for l in lines[start+1:end]]
304-
self.assertEqual(candidates, sorted(SQLITE_KEYWORDS))
309+
self.assertEqual(candidates, sorted(SQLITE_KEYWORDS + ('.help', '.quit', '.version')))
305310
except:
306311
if verbose:
307312
print(' PTY output: '.center(30, '-'))

0 commit comments

Comments
 (0)