Skip to content

gh-133390: Extend completion for .commands in sqlite3 #135432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Lib/sqlite3/_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
except ImportError:
SQLITE_KEYWORDS = ()

SQLITE_KEYWORDS += ('.quit', '.help', '.version')

_completion_matches = []


def _complete(text, state):
global _completion_matches

if state == 0:
text_upper = text.upper()
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
if text.startswith('.'):
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text)]
else:
text_upper = text.upper()
_completion_matches = [c for c in SQLITE_KEYWORDS if c.startswith(text_upper)]
try:
return _completion_matches[state] + " "
except IndexError:
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_sqlite3/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ def test_complete_sql_keywords(self):
self.assertIn(b"SELECT", output)
self.assertIn(b"(1,)", output)

# .commands are completed without changing case
input_ = b".ver\t\n.quit\n"
output = self.write_input(input_)
self.assertIn(b".version", output)

@unittest.skipIf(sys.platform.startswith("freebsd"),
"Two actual tabs are inserted when there are no matching"
" completions in the pseudo-terminal opened by run_pty()"
Expand Down Expand Up @@ -301,7 +306,7 @@ def test_complete_no_input(self):
self.assertEqual(len(indices), 2)
start, end = indices
candidates = [l.strip() for l in lines[start+1:end]]
self.assertEqual(candidates, sorted(SQLITE_KEYWORDS))
self.assertEqual(candidates, sorted(SQLITE_KEYWORDS + ('.help', '.quit', '.version')))
except:
if verbose:
print(' PTY output: '.center(30, '-'))
Expand Down
Loading