Skip to content

Commit d5ab1a1

Browse files
committed
Improve CLI help with examples and better descriptions
Add comprehensive help text at all levels: - Main command shows quick start examples and common workflows - Each subcommand group shows relevant examples - Individual commands show usage examples in after_help - Better parameter descriptions explain purpose and usage Add color-print crate for styled examples in main help.
1 parent 7d3c2c7 commit d5ab1a1

9 files changed

Lines changed: 255 additions & 94 deletions

File tree

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "src/main.rs"
1010

1111
[dependencies]
1212
clap = { version = "4", features = ["derive"] }
13+
color-print = "0.3"
1314
serde = { version = "1", features = ["derive"] }
1415
serde_json = "1"
1516
dirs = "6"

src/commands/alias.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,53 @@ use colored::Colorize;
44

55
#[derive(Subcommand)]
66
pub enum AliasCommand {
7-
/// Add or update an alias
7+
/// Configure a new alias for API or direct database access
8+
#[command(after_help = "Examples:\n \
9+
ow alias set prod --api https://dash.openworkers.com\n \
10+
ow alias set local --db postgres://localhost/ow --user admin@example.com\n \
11+
ow alias set dev --api https://localhost:8080 --insecure")]
812
Set {
9-
/// Alias name
13+
/// Alias name (used as prefix: ow <alias> workers list)
1014
name: String,
1115

12-
/// API URL (for API backend)
16+
/// API URL for HTTP backend (e.g., https://dash.openworkers.com)
1317
#[arg(long, conflicts_with = "db")]
1418
api: Option<String>,
1519

16-
/// API token
20+
/// API token (obtained via ow login)
1721
#[arg(long, requires = "api")]
1822
token: Option<String>,
1923

20-
/// Accept invalid TLS certificates (for dev environments)
24+
/// Accept invalid TLS certificates (for local development)
2125
#[arg(long, requires = "api")]
2226
insecure: bool,
2327

24-
/// Database URL (for DB backend)
28+
/// PostgreSQL URL for direct database access
2529
#[arg(long, conflicts_with = "api")]
2630
db: Option<String>,
2731

28-
/// User email or username to operate as (for DB backend)
32+
/// User email to operate as (required for db backend)
2933
#[arg(long, requires = "db")]
3034
user: Option<String>,
3135

32-
/// Overwrite existing alias
36+
/// Overwrite existing alias without confirmation
3337
#[arg(short, long)]
3438
force: bool,
3539
},
3640

37-
/// List all configured aliases
41+
/// List all configured aliases (* = default)
3842
#[command(alias = "ls")]
3943
List,
4044

41-
/// Remove an alias
42-
#[command(alias = "rm")]
45+
/// Remove an alias from configuration
46+
#[command(alias = "rm", after_help = "Example:\n ow alias remove old-prod")]
4347
Remove {
4448
/// Alias name to remove
4549
name: String,
4650
},
4751

48-
/// Set the default alias
52+
/// Set the default alias (used when no alias prefix is given)
53+
#[command(after_help = "Example:\n ow alias set-default prod")]
4954
SetDefault {
5055
/// Alias name to set as default
5156
name: String,

src/commands/databases.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,40 @@ use colored::Colorize;
44

55
#[derive(Subcommand)]
66
pub enum DatabasesCommand {
7-
/// List all databases
7+
/// List all database configurations
88
#[command(alias = "ls")]
99
List,
1010

11-
/// Get database details
11+
/// Show database configuration details
12+
#[command(after_help = "Example:\n ow databases get my-db")]
1213
Get {
1314
/// Database name
1415
name: String,
1516
},
1617

17-
/// Create a new database
18+
/// Create a database configuration for SQL access from workers
19+
#[command(after_help = "Examples:\n \
20+
ow databases create my-db\n \
21+
ow databases create my-db --provider postgres \\\n \
22+
--connection-string postgres://user:pass@host/db\n \
23+
ow databases create analytics --max-rows 5000 --timeout 60")]
1824
Create {
19-
/// Database name
25+
/// Database configuration name
2026
name: String,
2127

22-
/// Provider: platform (default) or postgres
28+
/// Database provider: platform (managed) or postgres (bring your own)
2329
#[arg(long, default_value = "platform")]
2430
provider: String,
2531

26-
/// Postgres connection string (required for postgres provider)
32+
/// PostgreSQL connection string (required for postgres provider)
2733
#[arg(long)]
2834
connection_string: Option<String>,
2935

30-
/// Description
36+
/// Description of this database
3137
#[arg(short, long)]
3238
description: Option<String>,
3339

34-
/// Maximum rows per query (default: 1000)
40+
/// Maximum rows returned per query (default: 1000)
3541
#[arg(long)]
3642
max_rows: Option<i32>,
3743

@@ -40,10 +46,10 @@ pub enum DatabasesCommand {
4046
timeout: Option<i32>,
4147
},
4248

43-
/// Delete a database
44-
#[command(alias = "rm")]
49+
/// Delete a database configuration
50+
#[command(alias = "rm", after_help = "Example:\n ow databases delete old-db")]
4551
Delete {
46-
/// Database name
52+
/// Database name to delete
4753
name: String,
4854
},
4955
}

src/commands/env.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,84 @@ use colored::Colorize;
66

77
#[derive(Subcommand)]
88
pub enum EnvCommand {
9-
/// List all environments
9+
/// List all environments with their variable/binding counts
1010
#[command(alias = "ls")]
1111
List,
1212

13-
/// Get environment details
13+
/// Show environment details including all variables and bindings
14+
#[command(after_help = "Example:\n ow env get production")]
1415
Get {
1516
/// Environment name
1617
name: String,
1718
},
1819

19-
/// Create a new environment
20+
/// Create a new environment for organizing variables and bindings
21+
#[command(after_help = "Examples:\n \
22+
ow env create production\n \
23+
ow env create staging -d \"Staging environment\"")]
2024
Create {
2125
/// Environment name
2226
name: String,
2327

24-
/// Environment description
28+
/// Description of this environment's purpose
2529
#[arg(short, long)]
2630
description: Option<String>,
2731
},
2832

29-
/// Delete an environment
30-
#[command(alias = "rm")]
33+
/// Delete an environment and all its variables/bindings
34+
#[command(alias = "rm", after_help = "Example:\n ow env delete old-env")]
3135
Delete {
32-
/// Environment name
36+
/// Environment name to delete
3337
name: String,
3438
},
3539

36-
/// Set a variable or secret
40+
/// Set a variable or secret in an environment
41+
#[command(after_help = "Examples:\n \
42+
ow env set prod API_URL https://api.example.com\n \
43+
ow env set prod API_KEY sk-xxx --secret")]
3744
Set {
3845
/// Environment name
3946
env: String,
4047

41-
/// Variable key
48+
/// Variable name (conventionally UPPER_SNAKE_CASE)
4249
key: String,
4350

4451
/// Variable value
4552
value: String,
4653

47-
/// Mark as secret (value will be masked)
54+
/// Store as secret (value is encrypted and masked in output)
4855
#[arg(short, long)]
4956
secret: bool,
5057
},
5158

52-
/// Remove a variable or secret
59+
/// Remove a variable or secret from an environment
60+
#[command(after_help = "Example:\n ow env unset prod OLD_API_KEY")]
5361
Unset {
5462
/// Environment name
5563
env: String,
5664

57-
/// Variable key
65+
/// Variable name to remove
5866
key: String,
5967
},
6068

61-
/// Bind a resource to an environment
69+
/// Bind a resource (KV, database, storage) to an environment
70+
#[command(after_help = "Examples:\n \
71+
ow env bind prod KV my-cache --type kv\n \
72+
ow env bind prod DB my-database --type database\n \
73+
ow env bind prod ASSETS my-storage --type assets\n \
74+
ow env bind prod FILES my-storage --type storage")]
6275
Bind {
6376
/// Environment name
6477
env: String,
6578

66-
/// Binding name (e.g. ASSETS, MY_KV, MY_DB)
79+
/// Binding name (accessed as env.NAME in worker code)
6780
key: String,
6881

69-
/// Resource name to bind
82+
/// Resource name to bind (must exist)
7083
resource: String,
7184

72-
/// Binding type
73-
#[arg(short = 't', long, value_parser = ["assets", "storage", "kv", "database"])]
85+
/// Binding type: assets, storage, kv, or database
86+
#[arg(short = 't', long = "type", value_parser = ["assets", "storage", "kv", "database"])]
7487
binding_type: String,
7588
},
7689
}

src/commands/kv.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@ pub enum KvCommand {
88
#[command(alias = "ls")]
99
List,
1010

11-
/// Get KV namespace details
11+
/// Show KV namespace details
12+
#[command(after_help = "Example:\n ow kv get my-cache")]
1213
Get {
1314
/// KV namespace name
1415
name: String,
1516
},
1617

17-
/// Create a new KV namespace
18+
/// Create a new KV namespace for key-value storage
19+
#[command(after_help = "Examples:\n \
20+
ow kv create my-cache\n \
21+
ow kv create sessions -d \"User sessions\"")]
1822
Create {
1923
/// KV namespace name
2024
name: String,
2125

22-
/// Description
26+
/// Description of what this namespace stores
2327
#[arg(short, long)]
2428
description: Option<String>,
2529
},
2630

27-
/// Delete a KV namespace
28-
#[command(alias = "rm")]
31+
/// Delete a KV namespace and all its data
32+
#[command(alias = "rm", after_help = "Example:\n ow kv delete old-cache")]
2933
Delete {
30-
/// KV namespace name
34+
/// KV namespace name to delete
3135
name: String,
3236
},
3337
}

0 commit comments

Comments
 (0)