Skip to content

Commit 9293046

Browse files
author
chenliuyun
committed
docs: restructure README as a user manual (badges, TOC, features, install, quick start, contributing)
1 parent 63190ef commit 9293046

1 file changed

Lines changed: 126 additions & 28 deletions

File tree

README.md

Lines changed: 126 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,98 @@
1-
# switchbot-openapi-cli
1+
# @switchbot/openapi-cli
2+
3+
[![npm version](https://img.shields.io/npm/v/@switchbot/openapi-cli.svg)](https://www.npmjs.com/package/@switchbot/openapi-cli)
4+
[![npm downloads](https://img.shields.io/npm/dm/@switchbot/openapi-cli.svg)](https://www.npmjs.com/package/@switchbot/openapi-cli)
5+
[![license](https://img.shields.io/npm/l/@switchbot/openapi-cli.svg)](./LICENSE)
6+
[![node](https://img.shields.io/node/v/@switchbot/openapi-cli.svg)](https://nodejs.org)
7+
[![CI](https://github.com/chenliuyun/switchbot-openapi-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/chenliuyun/switchbot-openapi-cli/actions/workflows/ci.yml)
28

39
Command-line interface for the [SwitchBot API v1.1](https://github.com/OpenWonderLabs/SwitchBotAPI).
4-
List devices, query status, send control commands, run scenes, and manage webhooks from your terminal or shell scripts.
10+
List devices, query live status, send control commands, run scenes, and manage webhooks — all from your terminal or shell scripts.
11+
12+
- **npm package:** [`@switchbot/openapi-cli`](https://www.npmjs.com/package/@switchbot/openapi-cli)
13+
- **Source code:** [github.com/chenliuyun/switchbot-openapi-cli](https://github.com/chenliuyun/switchbot-openapi-cli)
14+
- **Issues / feature requests:** [GitHub Issues](https://github.com/chenliuyun/switchbot-openapi-cli/issues)
15+
16+
---
17+
18+
## Table of contents
19+
20+
- [Features](#features)
21+
- [Requirements](#requirements)
22+
- [Installation](#installation)
23+
- [Quick start](#quick-start)
24+
- [Credentials](#credentials)
25+
- [Global options](#global-options)
26+
- [Commands](#commands)
27+
- [`config`](#config--credential-management)
28+
- [`devices`](#devices--list-status-control)
29+
- [`scenes`](#scenes--run-manual-scenes)
30+
- [`webhook`](#webhook--receive-device-events-over-http)
31+
- [`completion`](#completion--shell-tab-completion)
32+
- [Output modes](#output-modes)
33+
- [Exit codes & error codes](#exit-codes--error-codes)
34+
- [Environment variables](#environment-variables)
35+
- [Scripting examples](#scripting-examples)
36+
- [Development](#development)
37+
- [Contributing](#contributing)
38+
- [License](#license)
39+
- [References](#references)
40+
41+
---
42+
43+
## Features
44+
45+
- 🔌 **Complete API coverage** — every `/v1.1` endpoint (devices, scenes, webhooks)
46+
- 📚 **Built-in catalog** — offline reference for every device type's supported commands, parameter formats, and status fields (no API call needed)
47+
- 🎨 **Dual output modes** — colorized tables by default; `--json` passthrough for `jq` and scripting
48+
- 🔐 **Secure credentials** — HMAC-SHA256 signed requests; config file written with `0600`; env-var override for CI
49+
- 🔍 **Dry-run mode** — preview every mutating request before it hits the API
50+
- 🧪 **Fully tested** — 282 Vitest tests, mocked axios, zero network in CI
51+
-**Shell completion** — Bash / Zsh / Fish / PowerShell
552

653
## Requirements
754

8-
- Node.js ≥ 18
9-
- A SwitchBot account with Developer Options enabled (see [Credentials](#credentials))
55+
- **Node.js ≥ 18**
56+
- A SwitchBot account with **Developer Options** enabled (see [Credentials](#credentials))
1057

1158
## Installation
1259

60+
### From npm (recommended)
61+
62+
```bash
63+
npm install -g @switchbot/openapi-cli
64+
```
65+
66+
This adds the `switchbot` binary to your `$PATH`.
67+
68+
### From source
69+
1370
```bash
14-
git clone <repo-url>
71+
git clone https://github.com/chenliuyun/switchbot-openapi-cli.git
1572
cd switchbot-openapi-cli
1673
npm install
1774
npm run build
18-
# Optional: make it globally available as `switchbot`
19-
npm link
75+
npm link # optional — expose `switchbot` globally
76+
```
77+
78+
Verify:
79+
80+
```bash
81+
switchbot --version
82+
switchbot --help
2083
```
2184

22-
During development you can run directly from sources without building:
85+
## Quick start
2386

2487
```bash
25-
npm run dev -- devices list
88+
# 1. Save your credentials (one-time)
89+
switchbot config set-token <token> <secret>
90+
91+
# 2. List every device on your account
92+
switchbot devices list
93+
94+
# 3. Control a device
95+
switchbot devices command <deviceId> turnOn
2696
```
2797

2898
## Credentials
@@ -49,15 +119,15 @@ switchbot config show
49119

50120
## Global options
51121

52-
| Option | Description |
53-
| ------------------- | ------------------------------------------------------------------ |
54-
| `--json` | Print the raw JSON response instead of a formatted table |
55-
| `-v`, `--verbose` | Log HTTP request/response details to stderr |
56-
| `--dry-run` | Print mutating requests (POST/PUT/DELETE) without sending them |
57-
| `--timeout <ms>` | HTTP request timeout in milliseconds (default: `30000`) |
58-
| `--config <path>` | Override credential file location (default: `~/.switchbot/config.json`) |
59-
| `-V`, `--version` | Print the CLI version |
60-
| `-h`, `--help` | Show help for any command or subcommand |
122+
| Option | Description |
123+
| ------------------- | ------------------------------------------------------------------------ |
124+
| `--json` | Print the raw JSON response instead of a formatted table |
125+
| `-v`, `--verbose` | Log HTTP request/response details to stderr |
126+
| `--dry-run` | Print mutating requests (POST/PUT/DELETE) without sending them |
127+
| `--timeout <ms>` | HTTP request timeout in milliseconds (default: `30000`) |
128+
| `--config <path>` | Override credential file location (default: `~/.switchbot/config.json`) |
129+
| `-V`, `--version` | Print the CLI version |
130+
| `-h`, `--help` | Show help for any command or subcommand |
61131

62132
Every subcommand supports `--help`, and most include a parameter-format reference and examples.
63133

@@ -198,12 +268,12 @@ Supported shells: `bash`, `zsh`, `fish`, `powershell` (`pwsh` is accepted as an
198268
switchbot devices list --json | jq '.deviceList[] | {id: .deviceId, name: .deviceName}'
199269
```
200270

201-
## Exit codes
271+
## Exit codes & error codes
202272

203-
| Code | Meaning |
204-
| ---- | ----------------------------------------------------------------------------------- |
205-
| `0` | Success (including `--dry-run` intercept) |
206-
| `1` | Runtime error — API error, network failure, missing credentials |
273+
| Code | Meaning |
274+
| ---- | ------------------------------------------------------------------------------------------------------------------------- |
275+
| `0` | Success (including `--dry-run` intercept) |
276+
| `1` | Runtime error — API error, network failure, missing credentials |
207277
| `2` | Usage error — bad flag, missing/invalid argument, unknown subcommand, unknown device type, invalid URL, conflicting flags |
208278

209279
Typical errors bubble up in the form `Error: <message>` on stderr. The SwitchBot-specific error codes that get mapped to readable English messages:
@@ -242,11 +312,15 @@ switchbot scenes list --json | jq -r '.[] | "\(.sceneId) \(.sceneName)"'
242312
## Development
243313

244314
```bash
245-
npm run dev -- <args> # Run from TypeScript sources via tsx
246-
npm run build # Compile to dist/
247-
npm test # Run the Vitest suite (282 tests)
248-
npm run test:watch # Watch mode
249-
npm run test:coverage # Coverage report (v8, HTML + text)
315+
git clone https://github.com/chenliuyun/switchbot-openapi-cli.git
316+
cd switchbot-openapi-cli
317+
npm install
318+
319+
npm run dev -- <args> # Run from TypeScript sources via tsx
320+
npm run build # Compile to dist/
321+
npm test # Run the Vitest suite (282 tests)
322+
npm run test:watch # Watch mode
323+
npm run test:coverage # Coverage report (v8, HTML + text)
250324
```
251325

252326
### Project layout
@@ -271,6 +345,30 @@ src/
271345
tests/ # Vitest suite (282 tests, mocked axios, no network)
272346
```
273347

348+
### Release flow
349+
350+
Releases are cut on tag push and published to npm by GitHub Actions:
351+
352+
```bash
353+
npm version patch # bump version + create git tag
354+
git push --follow-tags
355+
```
356+
357+
Then on GitHub → **Releases → Draft a new release → select tag → Publish**. The `publish.yml` workflow runs tests, verifies the tag matches `package.json`, and publishes `@switchbot/openapi-cli` to npm with [provenance](https://docs.npmjs.com/generating-provenance-statements).
358+
359+
## Contributing
360+
361+
Bug reports, feature requests, and PRs are welcome.
362+
363+
1. Fork the repo and create a topic branch.
364+
2. Keep changes small and focused; add or update Vitest cases for any behavior change.
365+
3. Run `npm test` and `npm run build` locally — both must pass.
366+
4. Open a pull request against `main`. CI runs on Node 18/20/22; all three must stay green.
367+
368+
## License
369+
370+
[MIT](./LICENSE) © chenliuyun
371+
274372
## References
275373

276374
- [SwitchBot API v1.1 documentation](https://github.com/OpenWonderLabs/SwitchBotAPI)

0 commit comments

Comments
 (0)