Skip to content

Commit 17e5a2c

Browse files
sdairsclaude
andcommitted
Add CONTEXT FOR AGENTS sections to all CLI help screens
Adds after_help blocks to every command and subcommand in the CLI, giving LLM agents workflow context, argument syntax, and navigation hints when they invoke --help. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c32ee7f commit 17e5a2c

3 files changed

Lines changed: 168 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chv"
3-
version = "0.1.3"
3+
version = "0.1.5"
44
edition = "2024"
55

66
[dependencies]

src/cli.rs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ use clap::{Args, Parser, Subcommand};
44
#[command(name = "chv")]
55
#[command(about = "ClickHouse version manager", long_about = None)]
66
#[command(version)]
7+
#[command(after_help = "\
8+
CONTEXT FOR AGENTS:
9+
chv is a CLI to work with local ClickHouse and ClickHouse Cloud.
10+
11+
Two main workflows:
12+
1. Local: Install and interact with versions of ClickHouse to develop locally.
13+
2. Cloud: Manage ClickHouse Cloud infrastructure and push local work to cloud.
14+
15+
You can install the ClickHouse Agent Skills for best practices on using ClikHouse:
16+
17+
`npx skills add clickhouse/agent-skills`
18+
19+
Typical local workflow: `chv install stable && chv use stable && chv run server`.
20+
21+
Use `chv <command> --help` to get more context for specific commands.")]
722
pub struct Cli {
823
#[command(subcommand)]
924
pub command: Commands,
@@ -12,40 +27,91 @@ pub struct Cli {
1227
#[derive(Subcommand)]
1328
pub enum Commands {
1429
/// Install a ClickHouse version
30+
#[command(after_help = "\
31+
CONTEXT FOR AGENTS:
32+
Downloads a ClickHouse binary to ~/.clickhouse/versions/{version}/.
33+
Accepts version specs: \"stable\", \"lts\", partial like \"25.12\", or exact like \"25.12.5.44\".
34+
Optionally set as default with `chv use <version>`.
35+
`chv use <version>` will auto-install if the version is missing and set as default.
36+
Related: `chv list --available` to see downloadable versions.")]
1537
Install {
1638
/// Version to install (e.g., 25.1.2.3, 25.1, stable, lts)
1739
version: String,
1840
},
1941

2042
/// List installed versions
43+
#[command(after_help = "\
44+
CONTEXT FOR AGENTS:
45+
Without flags: shows locally installed versions (exact version strings).
46+
With --available: shows versions available for download from GitHub releases.
47+
Use the exact version strings from this output with `chv remove` or `chv use`.
48+
Related: `chv install <version>` to install, `chv which` to see current default.")]
2149
List {
2250
/// List versions available for download
2351
#[arg(long)]
2452
available: bool,
2553
},
2654

2755
/// Set the default version
56+
#[command(after_help = "\
57+
CONTEXT FOR AGENTS:
58+
Sets the default ClickHouse version used by `chv run` commands.
59+
Accepts version specs: \"stable\", \"lts\", partial like \"25.12\", or exact like \"25.12.5.44\".
60+
Auto-installs the version if not already present.
61+
Related: `chv which` to verify, `chv run server` to start.")]
2862
Use {
2963
/// Version to use as default
3064
version: String,
3165
},
3266

3367
/// Remove an installed version
68+
#[command(after_help = "\
69+
CONTEXT FOR AGENTS:
70+
Removes an installed ClickHouse version from ~/.clickhouse/versions/.
71+
Takes an exact version string as shown by `chv list` (e.g., \"25.12.5.44\").
72+
Does NOT accept keywords like \"stable\" — use the exact version number.
73+
Related: `chv list` to see installed versions.")]
3474
Remove {
3575
/// Version to remove
3676
version: String,
3777
},
3878

3979
/// Show the current default version
80+
#[command(after_help = "\
81+
CONTEXT FOR AGENTS:
82+
Shows the current default version and binary path. No arguments needed.
83+
Use this to verify which version is active before running commands.
84+
Related: `chv use <version>` to change the default.")]
4085
Which,
4186

4287
/// Initialize a project-local ClickHouse configuration
88+
#[command(after_help = "\
89+
CONTEXT FOR AGENTS:
90+
Creates a .clickhouse/ directory in the current working directory.
91+
Auto-called by `chv run server`, so rarely needed manually.
92+
Project data is scoped by version in .clickhouse/{version}/.
93+
Related: `chv run server` to start a server with project-local data.")]
4394
Init,
4495

4596
/// Run ClickHouse commands
97+
#[command(after_help = "\
98+
CONTEXT FOR AGENTS:
99+
Used for interacting with ClickHouse (local and Cloud).
100+
Gateway to server/client/local subcommands. Requires a default version set via `chv use`.
101+
Shortcut: `chv run --sql 'SELECT 1'` runs a query via clickhouse-local without subcommands to test things that don't need persistence.
102+
Pass extra ClickHouse args after -- (e.g., `chv run server -- --http_port=9000`).
103+
Related: `chv use <version>` to set default, `chv which` to check current version.")]
46104
Run(RunArgs),
47105

48106
/// ClickHouse Cloud API commands
107+
#[command(after_help = "\
108+
CONTEXT FOR AGENTS:
109+
Used for managing ClickHouse Cloud infrastructure.
110+
Gateway to org/service/backup subcommands for ClickHouse Cloud.
111+
Requires credentials via env vars CLICKHOUSE_CLOUD_API_KEY + CLICKHOUSE_CLOUD_API_SECRET, or via --api-key and --api-secret flags. Verify auth with `chv cloud org list`.
112+
Add --json to any cloud command for machine-readable output.
113+
Typical workflow: `cloud org list` → get org ID → `cloud service list` → manage services.
114+
Related: `chv cloud org list` to start.")]
49115
Cloud(CloudArgs),
50116
}
51117

@@ -62,20 +128,40 @@ pub struct RunArgs {
62128
#[derive(Subcommand)]
63129
pub enum RunCommands {
64130
/// Run clickhouse-server
131+
#[command(after_help = "\
132+
CONTEXT FOR AGENTS:
133+
Starts clickhouse-server with project-local data in .clickhouse/{version}/.
134+
Auto-initializes the data directory on first run. Replaces the current process (exec).
135+
Pass extra clickhouse-server args after -- (e.g., `chv run server -- --http_port=9000`).
136+
Data persists in .clickhouse/{version}/ between runs.
137+
Related: `chv run client` to connect, `chv use <version>` to change version.")]
65138
Server {
66139
/// Arguments to pass to clickhouse-server
67140
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
68141
args: Vec<String>,
69142
},
70143

71144
/// Run clickhouse-client
145+
#[command(after_help = "\
146+
CONTEXT FOR AGENTS:
147+
Connects to a running clickhouse-server. Server must already be running via `chv run server`.
148+
Pass clickhouse-client args after -- (e.g., `chv run client -- --query 'SELECT 1'`).
149+
Common args: --host, --port, --query, --multiquery, --format.
150+
Related: `chv run server` to start a server first.")]
72151
Client {
73152
/// Arguments to pass to clickhouse-client
74153
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
75154
args: Vec<String>,
76155
},
77156

78157
/// Run clickhouse-local
158+
#[command(after_help = "\
159+
CONTEXT FOR AGENTS:
160+
Runs clickhouse-local for file/query processing without a server.
161+
Pass clickhouse-local args after -- (e.g., `chv run local -- --query 'SELECT 1'`).
162+
Shortcut: `chv run --sql 'SELECT 1'` does the same without the local subcommand.
163+
Useful for processing files, running queries against local data, or testing SQL.
164+
Related: `chv run --sql` for quick one-off queries.")]
79165
Local {
80166
/// Arguments to pass to clickhouse-local
81167
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
@@ -104,18 +190,37 @@ pub struct CloudArgs {
104190
#[derive(Subcommand)]
105191
pub enum CloudCommands {
106192
/// Organization commands
193+
#[command(after_help = "\
194+
CONTEXT FOR AGENTS:
195+
Manage ClickHouse Cloud organizations. Subcommands: list, get.
196+
Org IDs are needed for most service and backup operations.
197+
Start with `chv cloud org list` to discover available org IDs.
198+
Related: `chv cloud service list` (uses org ID).")]
107199
Org {
108200
#[command(subcommand)]
109201
command: OrgCommands,
110202
},
111203

112204
/// Service commands
205+
#[command(after_help = "\
206+
CONTEXT FOR AGENTS:
207+
Manage ClickHouse Cloud services. Subcommands: list, get, create, delete, start, stop.
208+
Most commands need a service ID — get it from `chv cloud service list`.
209+
Org ID is auto-detected if you have only one org; otherwise pass --org-id.
210+
Add --json for machine-readable output. All write operations are immediate.
211+
Related: `chv cloud org list` for org IDs, `chv cloud backup list` for service backups.")]
113212
Service {
114213
#[command(subcommand)]
115214
command: ServiceCommands,
116215
},
117216

118217
/// Backup commands
218+
#[command(after_help = "\
219+
CONTEXT FOR AGENTS:
220+
Manage ClickHouse Cloud backups. Subcommands: list, get.
221+
Requires a service ID — get it from `chv cloud service list`.
222+
Backup IDs from `backup list` can be used with `service create --backup-id` to restore.
223+
Related: `chv cloud service list` for service IDs.")]
119224
Backup {
120225
#[command(subcommand)]
121226
command: BackupCommands,
@@ -125,9 +230,21 @@ pub enum CloudCommands {
125230
#[derive(Subcommand)]
126231
pub enum OrgCommands {
127232
/// List organizations
233+
#[command(after_help = "\
234+
CONTEXT FOR AGENTS:
235+
Returns all organizations accessible with the current API credentials.
236+
Use this to find org IDs needed by service and backup commands.
237+
Add --json for machine-readable output.
238+
Related: `chv cloud service list` next.")]
128239
List,
129240

130241
/// Get organization details
242+
#[command(after_help = "\
243+
CONTEXT FOR AGENTS:
244+
Returns details for a single organization by ID.
245+
Get org IDs from `chv cloud org list`.
246+
Add --json for machine-readable output.
247+
Related: `chv cloud org list` to find org IDs.")]
131248
Get {
132249
/// Organization ID
133250
org_id: String,
@@ -137,13 +254,25 @@ pub enum OrgCommands {
137254
#[derive(Subcommand)]
138255
pub enum ServiceCommands {
139256
/// List all services
257+
#[command(after_help = "\
258+
CONTEXT FOR AGENTS:
259+
Lists all services in the organization. Org ID is auto-detected if only one org exists.
260+
Returns service IDs needed by get, delete, start, stop, and backup commands.
261+
Add --json for machine-readable output.
262+
Related: `chv cloud service get <id>` for full details.")]
140263
List {
141264
/// Organization ID (auto-detected if not specified)
142265
#[arg(long)]
143266
org_id: Option<String>,
144267
},
145268

146269
/// Get service details
270+
#[command(after_help = "\
271+
CONTEXT FOR AGENTS:
272+
Returns full service details: status, endpoints, scaling config, IP access list.
273+
Get the service ID from `chv cloud service list`.
274+
Add --json for machine-readable output.
275+
Related: `chv cloud service start/stop <id>` to change state.")]
147276
Get {
148277
/// Service ID
149278
service_id: String,
@@ -154,6 +283,13 @@ pub enum ServiceCommands {
154283
},
155284

156285
/// Create a new service
286+
#[command(after_help = "\
287+
CONTEXT FOR AGENTS:
288+
Creates a new ClickHouse Cloud service. Only --name is required; other fields have defaults.
289+
Returns the new service ID and initial password — save these.
290+
Typical: `chv cloud service create --name my-svc`.
291+
Defaults: provider=aws, region=us-east-1. Add --json for machine-readable output.
292+
Related: `chv cloud service get <id>` to check status after creation.")]
157293
Create {
158294
/// Service name (required)
159295
#[arg(long)]
@@ -237,6 +373,12 @@ pub enum ServiceCommands {
237373
},
238374

239375
/// Delete a service
376+
#[command(after_help = "\
377+
CONTEXT FOR AGENTS:
378+
Permanently deletes a ClickHouse Cloud service. This action is irreversible.
379+
Takes a service ID — get it from `chv cloud service list`.
380+
Add --json for machine-readable output.
381+
Related: `chv cloud service stop <id>` to idle instead of delete.")]
240382
Delete {
241383
/// Service ID
242384
service_id: String,
@@ -247,6 +389,12 @@ pub enum ServiceCommands {
247389
},
248390

249391
/// Start a service
392+
#[command(after_help = "\
393+
CONTEXT FOR AGENTS:
394+
Resumes a stopped/idled ClickHouse Cloud service.
395+
Takes a service ID — get it from `chv cloud service list`.
396+
Add --json for machine-readable output.
397+
Related: `chv cloud service get <id>` to check status, `chv cloud service stop <id>` to idle.")]
250398
Start {
251399
/// Service ID
252400
service_id: String,
@@ -257,6 +405,12 @@ pub enum ServiceCommands {
257405
},
258406

259407
/// Stop a service
408+
#[command(after_help = "\
409+
CONTEXT FOR AGENTS:
410+
Idles a ClickHouse Cloud service, stopping billing for compute.
411+
Data is preserved. Takes a service ID — get it from `chv cloud service list`.
412+
Add --json for machine-readable output.
413+
Related: `chv cloud service start <id>` to resume, `chv cloud service delete <id>` to remove.")]
260414
Stop {
261415
/// Service ID
262416
service_id: String,
@@ -270,6 +424,12 @@ pub enum ServiceCommands {
270424
#[derive(Subcommand)]
271425
pub enum BackupCommands {
272426
/// List backups for a service
427+
#[command(after_help = "\
428+
CONTEXT FOR AGENTS:
429+
Lists all backups for a given service. Requires a service ID from `chv cloud service list`.
430+
Returns backup IDs that can be used with `chv cloud service create --backup-id` to restore.
431+
Add --json for machine-readable output.
432+
Related: `chv cloud backup get` for details on a specific backup.")]
273433
List {
274434
/// Service ID
275435
service_id: String,
@@ -280,6 +440,12 @@ pub enum BackupCommands {
280440
},
281441

282442
/// Get backup details
443+
#[command(after_help = "\
444+
CONTEXT FOR AGENTS:
445+
Returns details for a specific backup. Requires service ID and backup ID.
446+
Get service IDs from `chv cloud service list`, backup IDs from `chv cloud backup list`.
447+
Add --json for machine-readable output.
448+
Related: `chv cloud service create --backup-id <id>` to restore from this backup.")]
283449
Get {
284450
/// Service ID
285451
service_id: String,

0 commit comments

Comments
 (0)