Skip to content

Commit a553065

Browse files
gh-133390: Extend completion for .commands in sqlite3 (GH-135432)
1 parent b8c90e7 commit a553065

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Lib/sqlite3/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
6060

6161
if not source or source.isspace():
6262
return False
63+
# Remember to update CLI_COMMANDS in _completer.py
6364
if source[0] == ".":
6465
match source[1:].strip():
6566
case "version":

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+
CLI_COMMANDS = ('.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 CLI_COMMANDS 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: 5 additions & 0 deletions
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()"

0 commit comments

Comments
 (0)