goke 2.0.33 → 6.1.0
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/LICENSE +21 -0
- package/README.md +395 -2
- package/dist/CAC.d.ts +98 -0
- package/dist/CAC.d.ts.map +1 -0
- package/dist/CAC.js +374 -0
- package/dist/Command.d.ts +124 -0
- package/dist/Command.d.ts.map +1 -0
- package/dist/Command.js +249 -0
- package/dist/Option.d.ts +32 -0
- package/dist/Option.d.ts.map +1 -0
- package/dist/Option.js +39 -0
- package/dist/__test__/coerce.test.d.ts +2 -0
- package/dist/__test__/coerce.test.d.ts.map +1 -0
- package/dist/__test__/coerce.test.js +331 -0
- package/dist/__test__/index.test.d.ts +2 -0
- package/dist/__test__/index.test.d.ts.map +1 -0
- package/dist/__test__/index.test.js +1005 -0
- package/dist/__test__/types.test-d.d.ts +2 -0
- package/dist/__test__/types.test-d.d.ts.map +1 -0
- package/dist/__test__/types.test-d.js +67 -0
- package/dist/coerce.d.ts +138 -0
- package/dist/coerce.d.ts.map +1 -0
- package/dist/coerce.js +415 -0
- package/dist/goke.d.ts +302 -0
- package/dist/goke.d.ts.map +1 -0
- package/dist/goke.js +938 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -1
- package/dist/mri.d.ts +15 -0
- package/dist/mri.d.ts.map +1 -0
- package/dist/mri.js +130 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +2 -0
- package/dist/standard-schema.d.ts +48 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/standard-schema.js +9 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +101 -0
- package/dist/wrap-json-schema.d.ts +31 -0
- package/dist/wrap-json-schema.d.ts.map +1 -0
- package/dist/wrap-json-schema.js +40 -0
- package/package.json +39 -49
- package/src/__test__/coerce.test.ts +411 -0
- package/src/__test__/index.test.ts +1322 -0
- package/src/__test__/types.test-d.ts +111 -0
- package/src/coerce.ts +538 -0
- package/src/goke.ts +1249 -0
- package/src/index.ts +16 -0
- package/src/mri.ts +164 -0
- package/dist/contsants.d.ts +0 -2
- package/dist/contsants.js +0 -11
- package/dist/contsants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -38
- package/dist/main.js.map +0 -1
- package/dist/start.d.ts +0 -3
- package/dist/start.js +0 -61
- package/dist/start.js.map +0 -1
- package/dist/support.d.ts +0 -13
- package/dist/support.js +0 -79
- package/dist/support.js.map +0 -1
- package/dist/web-ui/out/404.html +0 -1
- package/dist/web-ui/out/_next/static/chunks/624547151fe14c5886ddcd4de3f13000f1acb97e.cace702aef443595104e.js +0 -1
- package/dist/web-ui/out/_next/static/chunks/b0eaeda543a5885485befd3baa1d233c1355c939.2c40c6eda99672c7003d.js +0 -1
- package/dist/web-ui/out/_next/static/chunks/commons.072020bebb6e45dccaee.js +0 -1
- package/dist/web-ui/out/_next/static/chunks/f65a48b9.7cbe5b676557ffb10922.js +0 -1
- package/dist/web-ui/out/_next/static/chunks/framework.619a4f70c1d4d3a29cbc.js +0 -1
- package/dist/web-ui/out/_next/static/css/81dac334fdd14f7d18eb.css +0 -1
- package/dist/web-ui/out/_next/static/runtime/main-afdcd9c9d293eca41a6b.js +0 -1
- package/dist/web-ui/out/_next/static/runtime/polyfills-1b8d17ce58466fbb5d61.js +0 -1
- package/dist/web-ui/out/_next/static/runtime/webpack-1c5199ff66550d26e499.js +0 -1
- package/dist/web-ui/out/_next/static/wCJMDQtd0AOjyM3e3g3PP/_buildManifest.js +0 -1
- package/dist/web-ui/out/_next/static/wCJMDQtd0AOjyM3e3g3PP/_ssgManifest.js +0 -1
- package/dist/web-ui/out/_next/static/wCJMDQtd0AOjyM3e3g3PP/pages/_app.js +0 -1
- package/dist/web-ui/out/_next/static/wCJMDQtd0AOjyM3e3g3PP/pages/_error.js +0 -1
- package/dist/web-ui/out/_next/static/wCJMDQtd0AOjyM3e3g3PP/pages/index.js +0 -1
- package/dist/web-ui/out/favicon.ico +0 -0
- package/dist/web-ui/out/index.html +0 -1
- package/dist/web-ui/out/vercel.svg +0 -4
- package/src/contsants.ts +0 -9
- package/src/main.ts +0 -35
- package/src/start.ts +0 -43
- package/src/support.ts +0 -63
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) EGOIST <0x142857@gmail.com> (https://github.com/egoist)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,398 @@
|
|
|
1
|
-
#
|
|
1
|
+
# goke
|
|
2
2
|
|
|
3
|
+
A [cac](https://github.com/cacjs/cac)-inspired CLI framework for building command-line apps in JavaScript/TypeScript.
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
## Features
|
|
5
6
|
|
|
7
|
+
- **Super light-weight**: No dependency, just a single file.
|
|
8
|
+
- **Easy to learn**. There are only 4 APIs you need to learn for building simple CLIs: `cli.option` `cli.version` `cli.help` `cli.parse`.
|
|
9
|
+
- **Yet so powerful**. Enable features like default command, git-like subcommands, validation for required arguments and options, variadic arguments, dot-nested options, automated help message generation and so on.
|
|
10
|
+
- **Space-separated subcommands**: Support multi-word commands like `mcp login`, `git remote add`.
|
|
11
|
+
- **Schema-based type coercion**: Use Zod, Valibot, ArkType, or plain JSON Schema for automatic type coercion and TypeScript type inference. Description and default values are extracted from the schema automatically.
|
|
12
|
+
- **Developer friendly**. Written in TypeScript.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install goke
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Simple Parsing
|
|
23
|
+
|
|
24
|
+
Use goke as simple argument parser:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { goke } from 'goke'
|
|
28
|
+
import { z } from 'zod'
|
|
29
|
+
|
|
30
|
+
const cli = goke()
|
|
31
|
+
|
|
32
|
+
cli.option(
|
|
33
|
+
'--type [type]',
|
|
34
|
+
z.string().default('node').describe('Choose a project type'),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const parsed = cli.parse()
|
|
38
|
+
|
|
39
|
+
console.log(JSON.stringify(parsed, null, 2))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Display Help Message and Version
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { goke } from 'goke'
|
|
46
|
+
import { z } from 'zod'
|
|
47
|
+
|
|
48
|
+
const cli = goke()
|
|
49
|
+
|
|
50
|
+
cli.option(
|
|
51
|
+
'--type [type]',
|
|
52
|
+
z.string().default('node').describe('Choose a project type'),
|
|
53
|
+
)
|
|
54
|
+
cli.option('--name <name>', 'Provide your name')
|
|
55
|
+
|
|
56
|
+
cli.command('lint [...files]', 'Lint files').action((files, options) => {
|
|
57
|
+
console.log(files, options)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Display help message when `-h` or `--help` appears
|
|
61
|
+
cli.help()
|
|
62
|
+
// Display version number when `-v` or `--version` appears
|
|
63
|
+
cli.version('0.0.0')
|
|
64
|
+
|
|
65
|
+
cli.parse()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Many Commands with a Root Command
|
|
69
|
+
|
|
70
|
+
Use `''` as the command name to define a root command that runs when no subcommand is given. This is useful for CLIs that have a primary action alongside several subcommands:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { goke } from 'goke'
|
|
74
|
+
import { z } from 'zod'
|
|
75
|
+
|
|
76
|
+
const cli = goke('deploy')
|
|
77
|
+
|
|
78
|
+
// Root command — runs when user types just `deploy`
|
|
79
|
+
cli
|
|
80
|
+
.command('', 'Deploy the current project')
|
|
81
|
+
.option('--env <env>', z.string().default('production').describe('Target environment'))
|
|
82
|
+
.option('--dry-run', 'Preview without deploying')
|
|
83
|
+
.action((options) => {
|
|
84
|
+
console.log(`Deploying to ${options.env}...`)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// Subcommands
|
|
88
|
+
cli
|
|
89
|
+
.command('init', 'Initialize a new project')
|
|
90
|
+
.option('--template <template>', 'Project template')
|
|
91
|
+
.action((options) => {
|
|
92
|
+
console.log('Initializing project...')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
cli
|
|
96
|
+
.command('login', 'Authenticate with the server')
|
|
97
|
+
.action(() => {
|
|
98
|
+
console.log('Opening browser for login...')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
cli.command('logout', 'Clear saved credentials').action(() => {
|
|
102
|
+
console.log('Logged out')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
cli
|
|
106
|
+
.command('status', 'Show deployment status')
|
|
107
|
+
.option('--json', 'Output as JSON')
|
|
108
|
+
.action((options) => {
|
|
109
|
+
console.log('Fetching status...')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
cli
|
|
113
|
+
.command('logs <deploymentId>', 'Stream logs for a deployment')
|
|
114
|
+
.option('--follow', 'Follow log output')
|
|
115
|
+
.option('--lines <n>', z.number().default(100).describe('Number of lines'))
|
|
116
|
+
.action((deploymentId, options) => {
|
|
117
|
+
console.log(`Streaming logs for ${deploymentId}...`)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
cli.help()
|
|
121
|
+
cli.version('1.0.0')
|
|
122
|
+
cli.parse()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
deploy # runs root command (deploy to production)
|
|
127
|
+
deploy --env staging --dry-run # root command with options
|
|
128
|
+
deploy init --template react # subcommand
|
|
129
|
+
deploy login # subcommand
|
|
130
|
+
deploy logs abc123 --follow # subcommand with args + options
|
|
131
|
+
deploy --help # shows all commands
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Command-specific Options
|
|
135
|
+
|
|
136
|
+
You can attach options to a command.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { goke } from 'goke'
|
|
140
|
+
|
|
141
|
+
const cli = goke()
|
|
142
|
+
|
|
143
|
+
cli
|
|
144
|
+
.command('rm <dir>', 'Remove a dir')
|
|
145
|
+
.option('-r, --recursive', 'Remove recursively')
|
|
146
|
+
.action((dir, options) => {
|
|
147
|
+
console.log('remove ' + dir + (options.recursive ? ' recursively' : ''))
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
cli.help()
|
|
151
|
+
|
|
152
|
+
cli.parse()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Space-separated Subcommands
|
|
156
|
+
|
|
157
|
+
goke supports multi-word command names for git-like nested subcommands:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { goke } from 'goke'
|
|
161
|
+
|
|
162
|
+
const cli = goke('mycli')
|
|
163
|
+
|
|
164
|
+
cli.command('mcp login <url>', 'Login to MCP server').action((url) => {
|
|
165
|
+
console.log('Logging in to', url)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
cli.command('mcp logout', 'Logout from MCP server').action(() => {
|
|
169
|
+
console.log('Logged out')
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
cli
|
|
173
|
+
.command('git remote add <name> <url>', 'Add a git remote')
|
|
174
|
+
.action((name, url) => {
|
|
175
|
+
console.log('Adding remote', name, url)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
cli.help()
|
|
179
|
+
cli.parse()
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Schema-based Type Coercion
|
|
183
|
+
|
|
184
|
+
Pass a Standard Schema (like Zod) as the second argument to `.option()` for automatic type coercion. Description and default values are extracted from the schema:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import { goke } from 'goke'
|
|
188
|
+
import { z } from 'zod'
|
|
189
|
+
|
|
190
|
+
const cli = goke()
|
|
191
|
+
|
|
192
|
+
cli
|
|
193
|
+
.command('serve', 'Start server')
|
|
194
|
+
.option('--port <port>', z.number().describe('Port number'))
|
|
195
|
+
.option('--host [host]', z.string().default('localhost').describe('Hostname'))
|
|
196
|
+
.option('--workers <workers>', z.int().describe('Worker count'))
|
|
197
|
+
.option('--tags <tag>', z.array(z.string()).describe('Tags (repeatable)'))
|
|
198
|
+
.option('--verbose', 'Verbose output')
|
|
199
|
+
.action((options) => {
|
|
200
|
+
// options.port is number, options.host is string, etc.
|
|
201
|
+
console.log(options)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
cli.parse()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The second argument accepts any object implementing [Standard JSON Schema V1](https://github.com/standard-schema/standard-schema), including:
|
|
208
|
+
|
|
209
|
+
- **Zod** v4.2+ (e.g. `z.number()`, `z.string()`, `z.array(z.number())`)
|
|
210
|
+
- **Valibot**, **ArkType**, and other Standard Schema-compatible libraries
|
|
211
|
+
- **Plain JSON Schema** via `wrapJsonSchema({ type: "number", description: "Port" })`
|
|
212
|
+
|
|
213
|
+
### Brackets
|
|
214
|
+
|
|
215
|
+
When using brackets in command name, angled brackets indicate required command arguments, while square brackets indicate optional arguments.
|
|
216
|
+
|
|
217
|
+
When using brackets in option name, angled brackets indicate that a string / number value is required, while square brackets indicate that the value can also be `true`.
|
|
218
|
+
|
|
219
|
+
### Negated Options
|
|
220
|
+
|
|
221
|
+
To allow an option whose value is `false`, you need to manually specify a negated option:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
cli
|
|
225
|
+
.command('build [project]', 'Build a project')
|
|
226
|
+
.option('--no-config', 'Disable config file')
|
|
227
|
+
.option('--config <path>', 'Use a custom config file')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Variadic Arguments
|
|
231
|
+
|
|
232
|
+
The last argument of a command can be variadic. To make an argument variadic you have to add `...` to the start of argument name:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
cli
|
|
236
|
+
.command('build <entry> [...otherFiles]', 'Build your app')
|
|
237
|
+
.option('--foo', 'Foo option')
|
|
238
|
+
.action((entry, otherFiles, options) => {
|
|
239
|
+
console.log(entry)
|
|
240
|
+
console.log(otherFiles)
|
|
241
|
+
console.log(options)
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Dot-nested Options
|
|
246
|
+
|
|
247
|
+
Dot-nested options will be merged into a single option.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
cli
|
|
251
|
+
.command('build', 'desc')
|
|
252
|
+
.option('--env <env>', 'Set envs')
|
|
253
|
+
.example('--env.API_SECRET xxx')
|
|
254
|
+
.action((options) => {
|
|
255
|
+
console.log(options)
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Default Command
|
|
260
|
+
|
|
261
|
+
Register a command that will be used when no other command is matched.
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
cli
|
|
265
|
+
.command('[...files]', 'Build files')
|
|
266
|
+
.option('--minimize', 'Minimize output')
|
|
267
|
+
.action((files, options) => {
|
|
268
|
+
console.log(files)
|
|
269
|
+
console.log(options.minimize)
|
|
270
|
+
})
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Error Handling
|
|
274
|
+
|
|
275
|
+
To handle command errors globally:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
try {
|
|
279
|
+
cli.parse(process.argv, { run: false })
|
|
280
|
+
await cli.runMatchedCommand()
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error(error.stack)
|
|
283
|
+
process.exit(1)
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### With TypeScript
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { goke } from 'goke'
|
|
291
|
+
|
|
292
|
+
const cli = goke('my-program')
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## References
|
|
296
|
+
|
|
297
|
+
### CLI Instance
|
|
298
|
+
|
|
299
|
+
CLI instance is created by invoking the `goke` function:
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
import { goke } from 'goke'
|
|
303
|
+
const cli = goke()
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### goke(name?)
|
|
307
|
+
|
|
308
|
+
Create a CLI instance, optionally specify the program name which will be used to display in help and version message. When not set we use the basename of `argv[1]`.
|
|
309
|
+
|
|
310
|
+
#### cli.command(name, description, config?)
|
|
311
|
+
|
|
312
|
+
- Type: `(name: string, description: string) => Command`
|
|
313
|
+
|
|
314
|
+
Create a command instance. Supports space-separated subcommands like `mcp login`.
|
|
315
|
+
|
|
316
|
+
- `config.allowUnknownOptions`: `boolean` Allow unknown options in this command.
|
|
317
|
+
- `config.ignoreOptionDefaultValue`: `boolean` Don't use the options's default value in parsed options, only display them in help message.
|
|
318
|
+
|
|
319
|
+
#### cli.option(name, descriptionOrSchema?)
|
|
320
|
+
|
|
321
|
+
- Type: `(name: string, descriptionOrSchema?: string | StandardJSONSchemaV1) => CLI`
|
|
322
|
+
|
|
323
|
+
Add a global option. The second argument is either:
|
|
324
|
+
- A **string** used as the description text
|
|
325
|
+
- A **Standard Schema** (e.g. `z.number().describe('Port')`) — description and default are extracted from the schema automatically
|
|
326
|
+
|
|
327
|
+
#### cli.parse(argv?)
|
|
328
|
+
|
|
329
|
+
- Type: `(argv = process.argv) => ParsedArgv`
|
|
330
|
+
|
|
331
|
+
#### cli.version(version, customFlags?)
|
|
332
|
+
|
|
333
|
+
- Type: `(version: string, customFlags = '-v, --version') => CLI`
|
|
334
|
+
|
|
335
|
+
#### cli.help(callback?)
|
|
336
|
+
|
|
337
|
+
- Type: `(callback?: HelpCallback) => CLI`
|
|
338
|
+
|
|
339
|
+
#### cli.outputHelp()
|
|
340
|
+
|
|
341
|
+
- Type: `() => CLI`
|
|
342
|
+
|
|
343
|
+
#### cli.usage(text)
|
|
344
|
+
|
|
345
|
+
- Type: `(text: string) => CLI`
|
|
346
|
+
|
|
347
|
+
### Command Instance
|
|
348
|
+
|
|
349
|
+
#### command.option()
|
|
350
|
+
|
|
351
|
+
Basically the same as `cli.option` but this adds the option to specific command.
|
|
352
|
+
|
|
353
|
+
#### command.action(callback)
|
|
354
|
+
|
|
355
|
+
- Type: `(callback: ActionCallback) => Command`
|
|
356
|
+
|
|
357
|
+
#### command.alias(name)
|
|
358
|
+
|
|
359
|
+
- Type: `(name: string) => Command`
|
|
360
|
+
|
|
361
|
+
#### command.allowUnknownOptions()
|
|
362
|
+
|
|
363
|
+
- Type: `() => Command`
|
|
364
|
+
|
|
365
|
+
#### command.example(example)
|
|
366
|
+
|
|
367
|
+
- Type: `(example: CommandExample) => Command`
|
|
368
|
+
|
|
369
|
+
#### command.usage(text)
|
|
370
|
+
|
|
371
|
+
- Type: `(text: string) => Command`
|
|
372
|
+
|
|
373
|
+
### Events
|
|
374
|
+
|
|
375
|
+
Listen to commands:
|
|
376
|
+
|
|
377
|
+
```js
|
|
378
|
+
cli.on('command:foo', () => {
|
|
379
|
+
// Do something
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
cli.on('command:!', () => {
|
|
383
|
+
// Default command
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
cli.on('command:*', () => {
|
|
387
|
+
console.error('Invalid command: %s', cli.args.join(' '))
|
|
388
|
+
process.exit(1)
|
|
389
|
+
})
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Credits
|
|
393
|
+
|
|
394
|
+
goke is inspired by [cac](https://github.com/cacjs/cac) (Command And Conquer) by [EGOIST](https://github.com/egoist).
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
MIT
|
package/dist/CAC.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import Command, { GlobalCommand, CommandConfig, HelpCallback, CommandExample } from "./Command.js";
|
|
3
|
+
import { OptionConfig } from "./Option.js";
|
|
4
|
+
interface ParsedArgv {
|
|
5
|
+
args: ReadonlyArray<string>;
|
|
6
|
+
options: {
|
|
7
|
+
[k: string]: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
declare class CAC extends EventEmitter {
|
|
11
|
+
/** The program name to display in help and version message */
|
|
12
|
+
name: string;
|
|
13
|
+
commands: Command[];
|
|
14
|
+
globalCommand: GlobalCommand;
|
|
15
|
+
matchedCommand?: Command;
|
|
16
|
+
matchedCommandName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Raw CLI arguments
|
|
19
|
+
*/
|
|
20
|
+
rawArgs: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Parsed CLI arguments
|
|
23
|
+
*/
|
|
24
|
+
args: ParsedArgv['args'];
|
|
25
|
+
/**
|
|
26
|
+
* Parsed CLI options, camelCased
|
|
27
|
+
*/
|
|
28
|
+
options: ParsedArgv['options'];
|
|
29
|
+
showHelpOnExit?: boolean;
|
|
30
|
+
showVersionOnExit?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @param name The program name to display in help and version message
|
|
33
|
+
*/
|
|
34
|
+
constructor(name?: string);
|
|
35
|
+
/**
|
|
36
|
+
* Add a global usage text.
|
|
37
|
+
*
|
|
38
|
+
* This is not used by sub-commands.
|
|
39
|
+
*/
|
|
40
|
+
usage(text: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Add a sub-command
|
|
43
|
+
*/
|
|
44
|
+
command(rawName: string, description?: string, config?: CommandConfig): Command;
|
|
45
|
+
/**
|
|
46
|
+
* Add a global CLI option.
|
|
47
|
+
*
|
|
48
|
+
* Which is also applied to sub-commands.
|
|
49
|
+
*/
|
|
50
|
+
option(rawName: string, description: string, config?: OptionConfig): this;
|
|
51
|
+
/**
|
|
52
|
+
* Show help message when `-h, --help` flags appear.
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
help(callback?: HelpCallback): this;
|
|
56
|
+
/**
|
|
57
|
+
* Show version number when `-v, --version` flags appear.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
version(version: string, customFlags?: string): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add a global example.
|
|
63
|
+
*
|
|
64
|
+
* This example added here will not be used by sub-commands.
|
|
65
|
+
*/
|
|
66
|
+
example(example: CommandExample): this;
|
|
67
|
+
/**
|
|
68
|
+
* Output the corresponding help message
|
|
69
|
+
* When a sub-command is matched, output the help message for the command
|
|
70
|
+
* Otherwise output the global one.
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
outputHelp(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Output help for commands matching a prefix.
|
|
76
|
+
* Used when user types "mcp nonexistent" and we have "mcp login", "mcp status", etc.
|
|
77
|
+
*/
|
|
78
|
+
outputHelpForPrefix(prefix: string, matchingCommands: Command[]): void;
|
|
79
|
+
/**
|
|
80
|
+
* Output the version number.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
outputVersion(): void;
|
|
84
|
+
private setParsedInfo;
|
|
85
|
+
unsetMatchedCommand(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Parse argv
|
|
88
|
+
*/
|
|
89
|
+
parse(argv?: string[], {
|
|
90
|
+
/** Whether to run the action for matched command */
|
|
91
|
+
run, }?: {
|
|
92
|
+
run?: boolean | undefined;
|
|
93
|
+
}): ParsedArgv;
|
|
94
|
+
private mri;
|
|
95
|
+
runMatchedCommand(): any;
|
|
96
|
+
}
|
|
97
|
+
export default CAC;
|
|
98
|
+
//# sourceMappingURL=CAC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CAC.d.ts","sourceRoot":"","sources":["../src/CAC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,OAAO,EAAE,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,cAAc,EACf,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU1C,UAAU,UAAU;IAClB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,OAAO,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;KACjB,CAAA;CACF;AAED,cAAM,GAAI,SAAQ,YAAY;IAC5B,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,aAAa,EAAE,aAAa,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IACxB;;OAEG;IACH,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAE9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAE3B;;OAEG;gBACS,IAAI,SAAK;IAWrB;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM;IAKlB;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa;IAOrE;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY;IAKlE;;;OAGG;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,YAAY;IAO5B;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,SAAkB;IAMtD;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,cAAc;IAK/B;;;;;OAKG;IACH,UAAU;IAQV;;;OAGG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE;IAsB/D;;;OAGG;IACH,aAAa;IAIb,OAAO,CAAC,aAAa;IAgBrB,mBAAmB;IAKnB;;OAEG;IACH,KAAK,CACH,IAAI,WAAc,EAClB;IACE,oDAAoD;IACpD,GAAU,GACX;;KAAK,GACL,UAAU;IAwGb,OAAO,CAAC,GAAG;IA0HX,iBAAiB;CAsBlB;AAED,eAAe,GAAG,CAAA"}
|