Skip to content

Interactive help/man command in the CLI with Markdown rendering - #108042

Merged
alexey-milovidov merged 4 commits into
masterfrom
help-command-markdown-cli
Jun 24, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
help-command-markdown-cli

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Implements the CLI part of the "Interactive help in CLI" issue. The system.documentation table 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>) in clickhouse-client (interactive) or clickhouse-local looks the word up in system.documentation case-insensitively and renders its embedded documentation, formatted from Markdown, in the terminal:

  • When several entities share a name (e.g. file, which is a function, a table engine and a dictionary source), all of them are shown.
  • When nothing matches exactly, the client lists similar names (by substring and edit distance) and the entities whose documentation mentions the word.
  • Bare help prints a short usage summary.

A new TerminalMarkdownRenderer turns 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 same highlighted helper the line editor uses. When the output is not a terminal a deterministic plain-text rendering is produced. Intraword */_ (as in max_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 in clickhouse-local, while batch clickhouse-client still parses a query starting with help/man as 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):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added an interactive help command to clickhouse-client and clickhouse-local. Typing help <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

  • Merged into: 26.6.1.1192

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]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [03937f0]

Summary: ✅


AI Review

Summary

This PR adds an interactive help / man meta-command for clickhouse-client and clickhouse-local, backed by system.documentation, plus a terminal Markdown renderer and focused tests. I found no unresolved code-review findings in the current head; the previous bot threads are addressed and resolved.

Missing context / blind spots
  • ⚠️ Full CI was still RUNNING for commit 03937f06 when checked; completed Fast/unit/stateless jobs would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 20, 2026
Comment thread src/Client/TerminalMarkdownRenderer.cpp Resolved
…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]>
Comment thread src/Client/TerminalMarkdownRenderer.cpp Resolved
- 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]>
Comment thread src/Client/TerminalMarkdownRenderer.cpp Resolved
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 728/910 (80.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@rschu1ze rschu1ze left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@rschu1ze rschu1ze self-assigned this Jun 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 24, 2026
Merged via the queue into master with commit f54220d Jun 24, 2026
166 checks passed
@alexey-milovidov
alexey-milovidov deleted the help-command-markdown-cli branch June 24, 2026 01:58
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 24, 2026
alexey-milovidov added a commit that referenced this pull request Jun 24, 2026
Add changelog entries for PRs that landed on the 26.6 release line after
the first pass: #82414, #108042 (New Feature), #107428 (Improvement),
and #108128, #108288, #100205, #108029 (Bug Fix).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…kdown-cli

Interactive help/man command in the CLI with Markdown rendering
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive help in CLI

3 participants