Skip to content

Respond to help <term> on builtin special commands#1859

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/help-on-special-commands
Open

Respond to help <term> on builtin special commands#1859
rolandwalker wants to merge 1 commit intomainfrom
RW/help-on-special-commands

Conversation

@rolandwalker
Copy link
Copy Markdown
Contributor

@rolandwalker rolandwalker commented Apr 25, 2026

Description

In this implementation, the detail returned is the same as visible in the table returned from a plain help, but the change opens up the ability to add a longer help text for each special command.

Motivation: there is not enough room in the tabular summary, and details such as the -c argument to watch are undocumented. Some commands, such as watch, return longer help text when given with no argument. Others, such as \dt, perform a default action. help cmd gives a uniform interface.

Bugs and limitations:

  • help \G is ambiguous, so if help is desired on \G itself, the \G must be quoted.
  • help use now gives help for the mycli special command use. This should be a better choice than querying the server, since the special command is what is executed.

Example:

last image

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Apr 25, 2026
@rolandwalker rolandwalker force-pushed the RW/help-on-special-commands branch from 0008045 to 41fd5f2 Compare April 25, 2026 14:48
@rolandwalker rolandwalker force-pushed the RW/help-on-special-commands branch 2 times, most recently from 5ce148a to 4782d23 Compare April 25, 2026 14:56
logger = logging.getLogger(__name__)

COMMANDS = {}
CASE_SENSITIVE_COMMANDS = set()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this new case logic might be duplicating what already exists in register_special_command:

case_sensitive: bool = False,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is leveraging the same information, to make it possible to immediately and accurately look up a command, respecting case-sensitivity, in one step.

def _show_special_help(keyword: str) -> list[SQLResult]:
header = ['name', 'description', 'example']
description = '\n'.join(COMMANDS[keyword][2:4])
rows = [(keyword, description, '')]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the example column is always empty; is that for future use or should it be removed or populated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The columns are made to match the output of help when returned from the server. See help SELECT;. Yes, I hope to populate the examples where appropriate.

:param command: string
"""
# special case: allow help on the \edit command
if re.match(r'^([Hh][Ee][Ll][Pp])\s+(\\e|\\edit)\s*(;|\\G|\\g)?\s*$', command):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use re.IGNORECASE for this if desired

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately \edit is case-sensitive, though I don't know why it must be.

In this implementation, the detail returned is the same as visible in
the table returned from a plain "help", but the change opens up the
ability to add a longer help text for each special command.

Motivation: there is not enough room in the tabular summary, and details
such as the "-c" argument to "watch" are undocumented.  Some commands,
such as "watch", return longer help text when given with no argument.
Others, such as "\dt", perform a default action.  "help cmd" gives a
uniform interface.

Bugs and limitations:

 * "help \G" is ambiguous, so if help is desired on "\G" itself, the
   "\G" must be quoted.
 * "help use" now gives help for the mycli special command "use".
@rolandwalker rolandwalker force-pushed the RW/help-on-special-commands branch from 4782d23 to f34c1e5 Compare April 27, 2026 10:08
@rolandwalker rolandwalker requested a review from scottnemes April 27, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants