breadc 0.7.0 → 0.8.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 +1 -1
- package/README.md +16 -15
- package/dist/index.cjs +590 -458
- package/dist/index.d.ts +121 -109
- package/dist/index.mjs +589 -451
- package/package.json +10 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# Breadc
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/breadc) [](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml)
|
|
3
|
+
[](https://www.npmjs.com/package/breadc) [](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml) [](https://codecov.io/gh/yjl9903/Breadc)
|
|
4
4
|
|
|
5
|
-
Yet another Command Line Application Framework
|
|
5
|
+
Yet another Command Line Application Framework with fully strong **[TypeScript](https://www.typescriptlang.org/) support**.
|
|
6
|
+
|
|
7
|
+

|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
11
|
+ ⚡️ **Light-weight**: Only 40 kB (Unpacked).
|
|
10
|
-
+ 📖 **East to Learn**: Breadc is basically compatible with [cac](https://github.com/cacjs/cac) and there are only 5 APIs for building a CLI application: `
|
|
12
|
+
+ 📖 **East to Learn**: Breadc is basically compatible with [cac](https://github.com/cacjs/cac) and there are only 5 APIs for building a CLI application: `breadc`, `command`, `option`, `action`, `run`.
|
|
11
13
|
+ 💻 **TypeScript Infer**: IDE will automatically infer the type of your command action function.
|
|
12
14
|
|
|
13
15
|
## Installation
|
|
@@ -21,23 +23,22 @@ npm i breadc
|
|
|
21
23
|
Try [./examples/echo.ts](./examples/echo.ts).
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
|
-
import
|
|
26
|
+
import breadc from 'breadc'
|
|
25
27
|
|
|
26
|
-
const cli =
|
|
27
|
-
.option('--host
|
|
28
|
-
.option('--port
|
|
28
|
+
const cli = breadc('echo', { version: '1.0.0' })
|
|
29
|
+
.option('--host <host>', { default: 'localhost' })
|
|
30
|
+
.option('--port <port>', { default: '3000', cast: p => +p })
|
|
29
31
|
|
|
30
32
|
cli
|
|
31
33
|
.command('[message]', 'Say something!')
|
|
32
34
|
.action((message, option) => {
|
|
33
|
-
const host = option.host
|
|
34
|
-
const port = option.port
|
|
35
|
-
console.log(`Host: ${host}`)
|
|
36
|
-
console.log(`Port: ${port}`)
|
|
35
|
+
const host = option.host
|
|
36
|
+
const port = option.port
|
|
37
|
+
console.log(`Host: ${host}`)
|
|
38
|
+
console.log(`Port: ${port}`)
|
|
37
39
|
})
|
|
38
40
|
|
|
39
|
-
cli.run(process.argv.slice(2))
|
|
40
|
-
.catch(err => cli.logger.error(err.message))
|
|
41
|
+
cli.run(process.argv.slice(2)).catch(err => console.error(err))
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
If you are using IDEs that support TypeScript (like [Visual Studio Code](https://code.visualstudio.com/)), input something using `option`, and then you will find the `option` is automatically typed with `{ host: string, port: number }`. In the figure below, [Visual Studio Code](https://code.visualstudio.com/) will automatically infer that the type of `option.host` is `string` and the type of `option.port` is `number`.
|
|
@@ -60,7 +61,7 @@ cli
|
|
|
60
61
|
.option('--port')
|
|
61
62
|
.command('')
|
|
62
63
|
.action((option) => {
|
|
63
|
-
// The type of option is
|
|
64
|
+
// The type of option is only { port: boolean }
|
|
64
65
|
})
|
|
65
66
|
```
|
|
66
67
|
|
|
@@ -71,4 +72,4 @@ cli
|
|
|
71
72
|
|
|
72
73
|
## License
|
|
73
74
|
|
|
74
|
-
MIT License ©
|
|
75
|
+
MIT License © 2023 [XLor](https://github.com/yjl9903)
|