Skip to content

Improve client usability#21

Merged
sdairs merged 9 commits intomainfrom
client-server-name
Mar 10, 2026
Merged

Improve client usability#21
sdairs merged 9 commits intomainfrom
client-server-name

Conversation

@sdairs
Copy link
Copy Markdown
Collaborator

@sdairs sdairs commented Mar 9, 2026

Summary

  • Add --name flag to local client to connect to a specific named server (defaults to "default")
  • Promote --host, --port, --query, and --queries-file as first-class flags instead of requiring passthrough
  • Port is auto-detected from the named server if --port is not explicitly set
  • Use the server's ClickHouse version for client binary selection (prevents client/server version mismatch)
  • Distinguish "server not found" from "server not running" errors for better diagnostics

Usage

clickhousectl local client                              # Connects to "default" server
clickhousectl local client --name dev                   # Connects to "dev" server
clickhousectl local client --query "SHOW DATABASES"     # Run a query
clickhousectl local client --queries-file schema.sql    # Run queries from a file
clickhousectl local client --host remote --port 9000    # Connect to a specific host/port

Test plan

  • local server start then local client connects to "default" on correct port
  • local server start --name dev --tcp-port 9001 then local client --name dev connects on port 9001
  • local client --name nonexistent errors with "Server not found"
  • local server start --name test, local server stop test, then local client --name test errors with "Server not running"
  • local client --query "SELECT 1" executes and returns result
  • local client --queries-file test.sql executes queries from file
  • local client --host localhost --port 9000 connects using explicit host/port (bypasses server lookup)
  • Client binary matches the server's version, not the current default (start server with version A, change default to version B, local client still uses version A)

🤖 Generated with Claude Code

`clickhousectl local client --name dev` looks up the named server's
TCP port and passes it to clickhouse-client automatically. Defaults to
"default" if --name is not specified. Errors if the server is not
running.

Also fixes a stale `local run client` reference in CLAUDE.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for connecting clickhousectl local client to a running local server by its configured name, enabling automatic TCP port lookup for named servers (Issue #16).

Changes:

  • Add --name/-n option to clickhousectl local client (defaulting to "default").
  • Look up the named running server’s TCP port and pass it to the ClickHouse client invocation.
  • Update docs (README usage examples; fix stale command reference in CLAUDE.md).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/main.rs Implements server lookup by name and injects the discovered TCP port into the client command.
src/cli.rs Adds --name/-n flag to the local client subcommand and updates help text.
README.md Documents new local client --name usage.
CLAUDE.md Fixes an outdated local run client reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sdairs and others added 4 commits March 9, 2026 22:09
Instead of requiring passthrough (-- --query ...), these common
clickhouse-client options are now proper flags on `local client`.
Port is auto-detected from the named server if not explicitly set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Promotes the clickhouse-client --queries-file option as a first-class
flag for executing SQL from a file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When connecting by name, use the version the server was started with
(from server info) instead of the current default. This prevents
client/server version mismatches when running multiple servers across
different versions. Falls back to the default version only when --port
is explicitly set (bypassing server lookup).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Check all servers (not just running ones) so a stopped server gets
a "server not running" error instead of the misleading "not found".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sdairs sdairs changed the title Add --name flag to local client for server lookup Improve client usability Mar 9, 2026
@sdairs sdairs requested a review from Copilot March 9, 2026 22:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sdairs and others added 4 commits March 9, 2026 22:39
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Either --host or --port signals a direct connection, skipping named
server lookup. --host is now Option<String> so the code can detect
when it was explicitly set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- CLAUDE.md: update local subcommand list (run → client), fix exec()
  reference to point at local client instead of old run server
- README: remove clickhouse-local mention from intro (no longer exposed)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sdairs sdairs merged commit 6daae24 into main Mar 10, 2026
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