Skip to content

Commit 4ee1241

Browse files
authored
fix(cli): Skills/Auth CLI command quality of life improvements
1 parent 5b5421f commit 4ee1241

File tree

14 files changed

+261
-215
lines changed

14 files changed

+261
-215
lines changed

README.md

Lines changed: 125 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,177 @@
22

33
Command line interface for [Hotdata](https://www.hotdata.dev).
44

5-
## Installation
5+
## Install
66

7-
Build from source (requires Rust):
7+
**Homebrew**
8+
9+
```sh
10+
brew install hotdata-dev/tap/hotdata-cli
11+
```
12+
13+
**Binary (macOS, Linux)**
14+
15+
Download a binary from [Releases](https://github.com/hotdata-dev/hotdata-cli/releases).
16+
17+
**Build from source** (requires Rust)
818

919
```sh
1020
cargo build --release
1121
cp target/release/hotdata /usr/local/bin/hotdata
1222
```
1323

14-
## Getting Started
24+
## Connect
25+
26+
Run the following command to authenticate:
1527

1628
```sh
17-
# Initialize config
18-
hotdata init
29+
hotdata auth
30+
```
31+
32+
This launches a browser window where you can authorize the CLI to access your Hotdata account.
1933

20-
# Log in via browser
21-
hotdata auth login
34+
Alternatively, authenticate with an API key using the `--api-key` flag:
2235

23-
# Check auth status
24-
hotdata auth status
36+
```sh
37+
hotdata <command> --api-key <api_key>
2538
```
2639

40+
Or set the `HOTDATA_API_KEY` environment variable (also loaded from `.env` files):
41+
42+
```sh
43+
export HOTDATA_API_KEY=<api_key>
44+
hotdata <command>
45+
```
46+
47+
API key priority (lowest to highest): config file → `HOTDATA_API_KEY` env var → `--api-key` flag.
48+
2749
## Commands
2850

29-
### Workspaces
51+
| Command | Subcommands | Description |
52+
| :-- | :-- | :-- |
53+
| `auth` | `status`, `logout` | Authenticate (run without subcommand to log in) |
54+
| `workspaces` | `list`, `set`, `get`, `create`, `update` | Manage workspaces |
55+
| `connections` | `list`, `get`, `create`, `refresh`, `update`, `delete`, `new` | Manage connections |
56+
| `tables` | `list` | List tables and columns |
57+
| `datasets` | `list`, `create` | Manage uploaded datasets |
58+
| `query` | | Execute a SQL query |
59+
| `results` | `list` | Retrieve stored query results |
60+
| `skills` | `install`, `status` | Manage the hotdata-cli agent skill |
61+
62+
## Global options
63+
64+
| Option | Description | Type | Default |
65+
| :-- | :-- | :-- | :-- |
66+
| `--api-key` | API key (overrides env var and config) | string | |
67+
| `-v, --version` | Print version | boolean | |
68+
| `-h, --help` | Print help | boolean | |
69+
70+
## Workspaces
3071

3172
```sh
32-
hotdata workspace list [--format table|json|yaml]
73+
hotdata workspaces list [--format table|json|yaml]
74+
hotdata workspaces set [<workspace_id>]
3375
```
3476

35-
### Connections
77+
- `list` shows all workspaces with a `*` marker on the active one.
78+
- `set` switches the active workspace. Omit the ID for interactive selection.
79+
- The active workspace is used as the default for all commands that accept `--workspace-id`.
80+
81+
## Connections
3682

3783
```sh
38-
hotdata connections list <workspace_id> [--format table|json|yaml]
84+
hotdata connections list [--workspace-id <id>] [--format table|json|yaml]
85+
hotdata connections get <connection_id> [--workspace-id <id>] [--format yaml|json|table]
86+
hotdata connections refresh <connection_id> [--workspace-id <id>]
87+
hotdata connections new [--workspace-id <id>]
3988
```
4089

41-
### Tables
90+
- `list` returns `id`, `name`, `source_type` for each connection.
91+
- `refresh` triggers a schema refresh for a connection.
92+
- `new` launches an interactive connection creation wizard.
93+
94+
### Create a connection
4295

4396
```sh
44-
# List all tables in a workspace
45-
hotdata tables list <workspace_id> [--format table|json|yaml]
97+
# List available connection types
98+
hotdata connections create list [--format table|json|yaml]
99+
100+
# Inspect schema for a connection type
101+
hotdata connections create list <type_name> --format json
46102

47-
# List columns for a specific connection
48-
hotdata tables list <workspace_id> --connection-id <connection_id> [--format table|json|yaml]
103+
# Create a connection
104+
hotdata connections create --name "my-conn" --type postgres --config '{"host":"...","port":5432,...}'
49105
```
50106

51-
### Query
107+
## Tables
52108

53109
```sh
54-
hotdata query "<sql>" --workspace-id <workspace_id> [--connection <connection_id>] [--format table|json|csv]
110+
hotdata tables list [--workspace-id <id>] [--connection-id <id>] [--schema <pattern>] [--table <pattern>] [--limit <n>] [--cursor <token>] [--format table|json|yaml]
55111
```
56112

57-
## Releasing
58-
59-
Releases use a two-phase workflow wrapping [`cargo-release`](https://github.com/crate-ci/cargo-release).
113+
- Without `--connection-id`: lists all tables with `table`, `synced`, `last_sync`.
114+
- With `--connection-id`: includes column details (`column`, `data_type`, `nullable`).
115+
- `--schema` and `--table` support SQL `%` wildcard patterns.
116+
- Tables are displayed as `<connection>.<schema>.<table>` — use this format in SQL queries.
60117

61-
**Phase 1 — prepare**
118+
## Datasets
62119

63120
```sh
64-
scripts/release.sh prepare <version>
65-
# e.g. scripts/release.sh prepare 0.2.0
121+
hotdata datasets list [--workspace-id <id>] [--limit <n>] [--offset <n>] [--format table|json|yaml]
122+
hotdata datasets <dataset_id> [--workspace-id <id>] [--format table|json|yaml]
123+
hotdata datasets create --file data.csv [--label "My Dataset"] [--table-name my_dataset]
124+
hotdata datasets create --sql "SELECT ..." --label "My Dataset"
66125
```
67126

68-
This will:
69-
1. Create a `release/<version>` branch
70-
2. Bump the version in `Cargo.toml`, update `CHANGELOG.md`, and push the branch
71-
3. Open a GitHub pull request and launch it in the browser
127+
- Datasets are queryable as `datasets.main.<table_name>`.
128+
- `--file`, `--sql`, and `--query-id` are mutually exclusive.
129+
- Format is auto-detected from file extension or content.
130+
- Piped stdin is supported: `cat data.csv | hotdata datasets create --label "My Dataset"`
72131

73-
Squash and merge the PR into `main` when ready.
132+
## Query
74133

75-
**Phase 2 — finish**
134+
```sh
135+
hotdata query "<sql>" [--workspace-id <id>] [--connection <connection_id>] [--format table|json|csv]
136+
```
137+
138+
- Default format is `table`, which prints results with row count and execution time.
139+
- Use `--connection` to scope the query to a specific connection.
140+
141+
## Results
76142

77143
```sh
78-
scripts/release.sh finish
144+
hotdata results <result_id> [--workspace-id <id>] [--format table|json|csv]
145+
hotdata results list [--workspace-id <id>] [--limit <n>] [--offset <n>] [--format table|json|yaml]
79146
```
80147

81-
Run this from any branch after the PR is merged. It will switch to `main`, pull the latest, tag the release, and trigger the dist workflow.
148+
- Query results include a `result-id` in the table footer — use it to retrieve past results without re-running queries.
82149

83150
## Configuration
84151

85152
Config is stored at `~/.hotdata/config.yml` keyed by profile (default: `default`).
86153

87-
Environment variable overrides:
154+
| Variable | Description | Default |
155+
| :-- | :-- | :-- |
156+
| `HOTDATA_API_KEY` | API key (overrides config file) | |
157+
| `HOTDATA_API_URL` | API base URL | `https://api.hotdata.dev/v1` |
158+
| `HOTDATA_APP_URL` | App URL for browser login | `https://app.hotdata.dev` |
159+
160+
## Releasing
161+
162+
Releases use a two-phase workflow wrapping [`cargo-release`](https://github.com/crate-ci/cargo-release).
163+
164+
**Phase 1 — prepare**
165+
166+
```sh
167+
scripts/release.sh prepare <version>
168+
```
169+
170+
Creates a `release/<version>` branch, bumps the version, updates `CHANGELOG.md`, pushes the branch, and opens a pull request.
171+
172+
**Phase 2 — finish**
173+
174+
```sh
175+
scripts/release.sh finish
176+
```
88177

89-
| Variable | Description |
90-
|--------------------|------------------------------------------|
91-
| `HOTDATA_API_KEY` | API key (overrides config) |
92-
| `HOTDATA_API_URL` | API base URL (default: `https://api.hotdata.dev/v1`) |
93-
| `HOTDATA_APP_URL` | App URL for browser login (default: `https://app.hotdata.dev`) |
178+
Switches to `main`, pulls latest, tags the release, and triggers the dist workflow.

skills/hotdata-cli/SKILL.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
name: hotdata-cli
3-
description: Use this skill when the user wants to run hotdata CLI commands, query the HotData API, list workspaces, list connections, create connections, list tables, manage datasets, execute SQL queries, or interact with the hotdata service. Activate when the user says "run hotdata", "query hotdata", "list workspaces", "list connections", "create a connection", "list tables", "list datasets", "create a dataset", "upload a dataset", "execute a query", or asks you to use the hotdata CLI.
3+
description: Use this skill when the user wants to run hotdata CLI commands, query the Hotdata API, list workspaces, list connections, create connections, list tables, manage datasets, execute SQL queries, or interact with the hotdata service. Activate when the user says "run hotdata", "query hotdata", "list workspaces", "list connections", "create a connection", "list tables", "list datasets", "create a dataset", "upload a dataset", "execute a query", or asks you to use the hotdata CLI.
44
version: 0.1.4
55
---
66

7-
# HotData CLI Skill
7+
# Hotdata CLI Skill
88

9-
Use the `hotdata` CLI to interact with the HotData service. In this project, run it as:
9+
Use the `hotdata` CLI to interact with the Hotdata service. In this project, run it as:
1010

1111
```
1212
hotdata <command> [args]
@@ -16,13 +16,18 @@ Or if installed on PATH: `hotdata <command> [args]`
1616

1717
## Authentication
1818

19-
Config is stored in `~/.hotdata/config.yml` keyed by profile (default: `default`).
20-
API key can also be set via `HOTDATA_API_KEY` env var.
19+
Run `hotdata auth` to authenticate via browser login. Config is stored in `~/.hotdata/config.yml`.
20+
21+
API key resolution (lowest to highest priority):
22+
1. Config file (saved by `hotdata auth`)
23+
2. `HOTDATA_API_KEY` environment variable (or `.env` file)
24+
3. `--api-key <key>` flag (works on any command)
25+
2126
API URL defaults to `https://api.hotdata.dev/v1` or overridden via `HOTDATA_API_URL`.
2227

2328
## Workspace ID
2429

25-
All commands that accept `--workspace-id` are optional. If omitted, the first workspace saved during `hotdata auth login` is used as the default. **Omit `--workspace-id` unless you need to target a specific workspace.**
30+
All commands that accept `--workspace-id` are optional. If omitted, the active workspace is used. Use `hotdata workspaces set` to switch the active workspace interactively, or pass a workspace ID directly: `hotdata workspaces set <workspace_id>`. The active workspace is shown with a `*` marker in `hotdata workspaces list`. **Omit `--workspace-id` unless you need to target a specific workspace.**
2631

2732
## Available Commands
2833

@@ -111,7 +116,7 @@ hotdata tables list [--workspace-id <workspace_id>] [--connection-id <connection
111116

112117
### Datasets
113118

114-
Datasets are managed files uploaded to HotData and queryable as tables.
119+
Datasets are managed files uploaded to Hotdata and queryable as tables.
115120

116121
#### List datasets
117122
```
@@ -173,15 +178,10 @@ hotdata results <result_id> [--workspace-id <workspace_id>] [--format table|json
173178

174179
### Auth
175180
```
176-
hotdata auth login # Browser-based login
181+
hotdata auth # Browser-based login
177182
hotdata auth status # Check current auth status
178183
```
179184

180-
### Init
181-
```
182-
hotdata init # Create ~/.hotdata/config.yml
183-
```
184-
185185
## Workflow: Running a Query
186186

187187
1. List connections:

src/auth.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ use sha2::{Digest, Sha256};
88
use std::collections::HashMap;
99
use std::io::stdout;
1010

11+
pub fn logout(profile: &str) {
12+
if let Err(e) = config::remove_api_key(profile) {
13+
eprintln!("error: {e}");
14+
std::process::exit(1);
15+
}
16+
println!("{}", "Logged out.".green());
17+
}
18+
1119
pub fn status(profile: &str) {
1220
let profile_config = match config::load(profile) {
1321
Ok(c) => c,
@@ -133,7 +141,7 @@ pub fn login() {
133141
<head>
134142
<meta charset="UTF-8" />
135143
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
136-
<title>HotData — Login Successful</title>
144+
<title>Hotdata — Login Successful</title>
137145
<style>
138146
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
139147
body {
@@ -177,7 +185,7 @@ pub fn login() {
177185
</svg>
178186
</div>
179187
<h1>Login successful</h1>
180-
<p>You're now authenticated with HotData.<br/>You can close this tab and return to the terminal.</p>
188+
<p>You're now authenticated with Hotdata.<br/>You can close this tab and return to the terminal.</p>
181189
</div>
182190
</body>
183191
</html>"#;

0 commit comments

Comments
 (0)