@sdk-it/command 0.46.0 → 0.46.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @sdk-it/command
|
|
2
|
+
|
|
3
|
+
Build a Commander.js CLI directly from an OpenAPI document. Each operation
|
|
4
|
+
becomes a subcommand with validated flags, JSON-file input, stdin input, and
|
|
5
|
+
machine-readable output.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @sdk-it/command
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Create a CLI
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
#!/usr/bin/env node
|
|
17
|
+
import { command } from '@sdk-it/command';
|
|
18
|
+
|
|
19
|
+
const program = await command('./openapi.yaml', {
|
|
20
|
+
name: 'acme',
|
|
21
|
+
description: 'Acme API CLI',
|
|
22
|
+
version: '1.0.0',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await program.parseAsync();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The base URL is resolved from `options.baseUrl`, `ACME_BASE_URL`, or the first
|
|
29
|
+
OpenAPI `servers` entry. Bearer tokens come from `options.token`,
|
|
30
|
+
`ACME_TOKEN`, or the global `--token` option. Use `baseUrlEnv` and `tokenEnv`
|
|
31
|
+
to override the environment-variable names.
|
|
32
|
+
|
|
33
|
+
## Use the generated commands
|
|
34
|
+
|
|
35
|
+
Normalized operation names become command names, and operation inputs become
|
|
36
|
+
flags:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
acme listUsers --limit 20
|
|
40
|
+
acme createUser --name Alice --age 30
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For nested input that cannot be represented as flags, pass JSON by file or
|
|
44
|
+
stdin:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
acme createUser --input-file user.json
|
|
48
|
+
printf '{"name":"Alice"}' | acme createUser
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Inspect the available operation schemas without sending a request:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
acme schema
|
|
55
|
+
acme createUser --describe
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Global options include `--base-url`, `--token`, and `--output json|raw`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/command",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"!**/*.test.*"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@sdk-it/core": "0.46.
|
|
26
|
-
"@sdk-it/rpc": "0.46.
|
|
27
|
-
"@sdk-it/spec": "0.46.
|
|
28
|
-
"@sdk-it/typescript": "0.46.
|
|
25
|
+
"@sdk-it/core": "0.46.2",
|
|
26
|
+
"@sdk-it/rpc": "0.46.2",
|
|
27
|
+
"@sdk-it/spec": "0.46.2",
|
|
28
|
+
"@sdk-it/typescript": "0.46.2",
|
|
29
29
|
"commander": "^13.0.0",
|
|
30
30
|
"openapi3-ts": "4.5.0",
|
|
31
31
|
"zod": "^4.3.0"
|