Skip to content

Add global ~/.local/bin/clickhouse symlink on local use (#202)#204

Merged
sdairs merged 1 commit into
mainfrom
issue-202-global-symlink
May 22, 2026
Merged

Add global ~/.local/bin/clickhouse symlink on local use (#202)#204
sdairs merged 1 commit into
mainfrom
issue-202-global-symlink

Conversation

@sdairs
Copy link
Copy Markdown
Collaborator

@sdairs sdairs commented May 21, 2026

Summary

  • clickhousectl local use <version> now creates/updates ~/.local/bin/clickhouse as a symlink to the active binary, so clickhouse local, clickhouse client, etc. work without going via clickhousectl. Opt-out with --no-global.
  • local remove of the currently-default version also clears the symlink — but only if it still points into that version's directory, so a manually repointed link is preserved.
  • If a regular file (not a symlink) already exists at the path, it's left alone with a stderr warning — no silent clobbering of a user-managed install.
  • Unix-only via #[cfg(unix)]; non-unix builds get a no-op stub. Symlink failures are best-effort: they emit a stderr warning but never affect the command's exit status, so the default file always gets written.
  • After a successful symlink, the helper warns once if ~/.local/bin is not on $PATH.

Closes #202.

Test plan

  • cargo build -p clickhousectl — clean
  • cargo test -p clickhousectl — 9 new unit tests + existing suite green
  • cargo clippy -p clickhousectl --all-targets — no new warnings
  • local use stable → symlink created at ~/.local/bin/clickhouse pointing at the binary
  • local use lts --no-global → default updated, symlink unchanged
  • local use lts → symlink retargeted to LTS
  • Regular file at ~/.local/bin/clickhouse → warning printed, file untouched, default still set

🤖 Generated with Claude Code

`clickhousectl local use <version>` now creates a symlink at
`~/.local/bin/clickhouse` pointing to the active binary so the
`clickhouse` command is on PATH. Pass `--no-global` to skip.
`local remove` of the active default clears the symlink — but only
if it still points into the removed version's directory, so a
manually repointed symlink is preserved. If a regular file already
exists at the symlink path it's left alone with a stderr warning.
Unix-only; non-unix is a no-op. Best-effort throughout: failures
warn but never affect the command's exit status.

Co-Authored-By: Claude Opus 4.7 (1M context) <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 a “global” clickhouse entrypoint when selecting a local default ClickHouse version, by managing a ~/.local/bin/clickhouse symlink during clickhousectl local use (opt-out via --no-global) and cleaning it up on local remove when appropriate. This fits the local version-management workflow by enabling direct clickhouse ... invocation without going through clickhousectl.

Changes:

  • Add --no-global to clickhousectl local use and best-effort creation/update of ~/.local/bin/clickhouse symlink.
  • Clear the global symlink on local remove of the active default version (only when it still points into that version’s directory).
  • Document the behavior in the README and CLI help, and add a Unix-only symlink helper + unit tests.

Reviewed changes

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

Show a summary per file
File Description
README.md Documents the new global clickhouse symlink behavior and --no-global.
crates/clickhousectl/src/paths.rs Adds helpers for ~/.local/bin and the clickhouse symlink path.
crates/clickhousectl/src/local/symlink.rs Implements Unix-only symlink create/update/remove logic and unit tests.
crates/clickhousectl/src/local/mod.rs Wires symlink management into local use and local remove.
crates/clickhousectl/src/local/cli.rs Adds the --no-global flag and updates local use help text.

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

Comment thread README.md
Comment thread crates/clickhousectl/src/local/cli.rs
Comment thread crates/clickhousectl/src/local/symlink.rs
@sdairs sdairs merged commit c417087 into main May 22, 2026
3 checks passed
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.

Set a global clickhouse symlink to chctl default bin

3 participants