]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133390: Extend completion for .commands in `sqlite3` (GH-135432)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Mon, 25 Aug 2025 12:58:00 +0000 (13:58 +0100)
committerGitHub <noreply@github.com>
Mon, 25 Aug 2025 12:58:00 +0000 (14:58 +0200)
Lib/sqlite3/__main__.py
Lib/sqlite3/_completer.py
Lib/test/test_sqlite3/test_cli.py

index 35344ecceff5260527ce6ca8c48e3f3f25c0781c..093b38c00013873b2c51aef3f260e4f3b7b6aec0 100644 (file)
@@ -60,6 +60,7 @@ class SqliteInteractiveConsole(InteractiveConsole):
 
         if not source or source.isspace():
             return False
+        # Remember to update CLI_COMMANDS in _completer.py
         if source[0] == ".":
             match source[1:].strip():
                 case "version":
index f21ef69cad6439be1341488b5afc7fa42c5affef..b3e8c0e5f36208e7cf3d1a0be664d87fa74adc37 100644 (file)
@@ -5,6 +5,8 @@ try:
 except ImportError:
     SQLITE_KEYWORDS = ()
 
+CLI_COMMANDS = ('.quit', '.help', '.version')
+
 _completion_matches = []
 
 
@@ -12,8 +14,11 @@ 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 CLI_COMMANDS 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:
index 720fa3c4c1ea8b56e168c0010b6a784e2e42e04c..5926cec0569ddb26449cc7c107f04c44d889de62 100644 (file)
@@ -249,6 +249,11 @@ class Completion(unittest.TestCase):
         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()"