From a839478012eef73094fcd5732b13b12325f76d9d Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 25 Feb 2026 05:14:53 -0500 Subject: [PATCH] let "help " fall back to list similar terms when the term is not found. * parameterize the help query * no need to pass empty status property * search for %keyword% if exact search fails, and report those results as a table of similar terms * quote "keyword" in failure message --- changelog.md | 1 + mycli/packages/special/main.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 88f0fe3e..686d6175 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ Features * Let the `F1` key open a browser to mycli.net/docs and emit help text. * Add documentation index URL to inline help. * Rewrite bottom toolbar, showing more statuses, but staying compact. +* Let `help ` list similar keywords when not found. Bug Fixes diff --git a/mycli/packages/special/main.py b/mycli/packages/special/main.py index 3d30d9d5..3721564c 100644 --- a/mycli/packages/special/main.py +++ b/mycli/packages/special/main.py @@ -172,20 +172,25 @@ def show_help(*_args) -> list[SQLResult]: def show_keyword_help(cur: Cursor, arg: str) -> list[SQLResult]: """ - Call the built-in "show ", to display help for an SQL keyword. + Call the built-in "show ", to display help for an SQL keyword. :param cur: cursor :param arg: string :return: list """ - keyword = arg.strip('"').strip("'") - query = f"help '{keyword}'" + keyword = arg.strip().strip('"\'') + query = 'help %s' logger.debug(query) - cur.execute(query) + cur.execute(query, keyword) if cur.description and cur.rowcount > 0: headers = [x[0] for x in cur.description] - return [SQLResult(results=cur, headers=headers, status="")] + return [SQLResult(results=cur, headers=headers)] + logger.debug(query) + cur.execute(query, (f'%{keyword}%',)) + if cur.description and cur.rowcount > 0: + headers = [x[0] for x in cur.description] + return [SQLResult(title='Similar terms:', results=cur, headers=headers)] else: - return [SQLResult(status=f'No help found for {keyword}.')] + return [SQLResult(status=f'No help found for "{keyword}".')] @special_command('\\bug', '\\bug', 'File a bug on GitHub.', arg_type=ArgType.NO_QUERY)