Repository navigation
Interactive help/man command in the CLI with Markdown rendering - #108042
Conversation
Implements the CLI side of the interactive help feature: entering `help`, `/help`, `man` or `/man` followed by a name looks the word up in `system.documentation` (case-insensitive) and renders its embedded documentation, formatted from Markdown, in the terminal. - When several entities share a name (e.g. `file`), all of them are shown. - When nothing matches exactly, the client lists similar names (by substring and edit distance) and entities whose documentation mentions the word. - Bare `help` prints a short usage summary. A new `TerminalMarkdownRenderer` turns the Markdown into terminal output: ATX headers, paragraphs (word-wrapped), ordered/unordered lists, blockquotes, tables, and fenced code blocks, plus inline bold/italic/`code`/links. SQL code blocks are highlighted with the same `highlighted` helper the line editor uses. When the output is not a terminal a plain-text rendering is produced. Intraword `*`/`_` (e.g. in `max_threads`) are kept literal, not treated as emphasis. The command is gated like the other client meta-commands (`clear`, `ls`), so it is available in interactive mode and in `clickhouse-local`, while batch `clickhouse-client` still parses a query starting with `help`/`man` as SQL. Closes: #89377 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [03937f0] Summary: ✅
AI ReviewSummaryThis PR adds an interactive Missing context / blind spots
Final VerdictStatus: ✅ Approve |
…w fixes
Addresses CI failures and review feedback on the interactive help command:
- Fix a real bug surfaced by the new interactive test: `fetchDocumentation`
passed `client_info = nullptr` to `sendQuery`, which `clickhouse-local`
tolerates but the TCP server rejects ("Unexpected query kind in Query packet").
Pass a valid client info, so `help` works in `clickhouse-client` too.
- Fix the Fast test link error: the `help` functions were accidentally placed
inside `#if USE_CLIENT_AI`, so they were undefined when the AI client was off.
- When the SQL parser cannot parse a code block (documentation is full of query
fragments such as `f(x)` or `ENGINE = MergeTree`), fall back to lexer-based
highlighting instead of leaving it unhighlighted. The token kinds and colors
mirror the Web UI (`programs/server/play.html`); the line editor is unchanged.
- Renderer improvements: strip explicit header anchors (`{#anchor}`); render
`:::note` / `:::tip` / ... admonitions; hide MDX `import` lines and render
`<...Badge/>` components as readable labels; only treat `*`/`_` as emphasis
when a matching closer exists, so a lone `*` (e.g. `SELECT * FROM t`) stays
literal. Wrap to the full terminal width and frame the output with blank lines.
- Add an interactive test (`04402_help_command_interactive.py`) covering the
`clickhouse-client` path, and more renderer unit tests. Silence the style
check for the best-effort terminal-width `catch (...)`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- The `help` suggestion queries used `lowerUTF8`, which requires ICU. In builds without ICU (the Fast test build) those queries threw, so the "not found" path produced no output, failing both `04401_help_command` and the interactive `04402_help_command_interactive` (which timed out waiting for the message). Entity names are ASCII, so use `lower` instead — no ICU dependency. - Mark the `Renderer` constructor `explicit` (clang-tidy google-explicit-constructor, surfaced by the arm_tidy build). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ings Two issues found in review on the embedded documentation: - Admonition fences may use more than three colons (`::::note` ... `::::`, used in the settings docs). Count the opening colon run and close only on a colon run of the same length. A stray/bare close fence is now dropped while always advancing the parser, so it can never stall the render loop. - Fenced code blocks carry info-string attributes (e.g. ```sql title=Query, as emitted by `FunctionDocumentation`/`Documentation` examples). Take the first token of the info string as the language, so those blocks are SQL-highlighted instead of dimmed. Also support fences longer than three characters. Added renderer tests for `::::note`, a stray close fence, and ```sql title=Query. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 728/910 (80.00%) | Lost baseline coverage: none · Uncovered code |
rschu1ze
left a comment
There was a problem hiding this comment.
I tested the PR locally (it works well) and I reviewed everything in this PR except the GUnit test and the markdown renderer. It will be a bit of a maintenance hell :-) I found an alternative library https://github.com/ishanawal/TermMark/tree/main Anyways, green light from me.
…kdown-cli Interactive help/man command in the CLI with Markdown rendering
Add changelog entries for PRs that landed on the 26.6 release line after the first pass: ClickHouse#82414, ClickHouse#108042 (New Feature), ClickHouse#107428 (Improvement), and ClickHouse#108128, ClickHouse#108288, ClickHouse#100205, ClickHouse#108029 (Bug Fix). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Implements the CLI part of the "Interactive help in CLI" issue. The
system.documentationtable and the embedded-documentation prerequisite PRs (table engines, data types, formats, etc.) are already merged; this adds the client command that consumes them.Entering
help <name>(or the equivalent forms/help <name>,man <name>,/man <name>) inclickhouse-client(interactive) orclickhouse-locallooks the word up insystem.documentationcase-insensitively and renders its embedded documentation, formatted from Markdown, in the terminal:file, which is a function, a table engine and a dictionary source), all of them are shown.helpprints a short usage summary.A new
TerminalMarkdownRendererturns the Markdown into terminal output: ATX headers, word-wrapped paragraphs, ordered/unordered lists, blockquotes, tables, and fenced code blocks, plus inline bold/italic/code/links. SQL code blocks are highlighted with the samehighlightedhelper the line editor uses. When the output is not a terminal a deterministic plain-text rendering is produced. Intraword*/_(as inmax_threads) are kept literal rather than treated as emphasis.The command is gated like the other client meta-commands (
clear,ls), so it is available in interactive mode and inclickhouse-local, while batchclickhouse-clientstill parses a query starting withhelp/manas SQL.Tested by a new gtest for the renderer (
src/Client/tests/gtest_terminal_markdown_renderer.cpp) and a functional test (tests/queries/0_stateless/04401_help_command.sh).Closes: #89377
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added an interactive
helpcommand toclickhouse-clientandclickhouse-local. Typinghelp <name>(also/help,man,/man) shows the documentation of a function, table engine, data type, format, setting, and other components, rendered from Markdown in the terminal with syntax-highlighted SQL. When the word is ambiguous all matches are shown, and when it is not found similar names and matching documentation text are suggested.Version info
26.6.1.1192