breadc 0.1.0 → 0.3.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![version](https://img.shields.io/npm/v/breadc?color=rgb%2850%2C203%2C86%29&label=Breadc)](https://www.npmjs.com/package/breadc) [![CI](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml/badge.svg)](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml)
4
4
 
5
- Yet another Command Line Application Framework powered by [minimist](https://www.npmjs.com/package/minimist), but with fully [TypeScript](https://www.typescriptlang.org/) support.
5
+ Yet another Command Line Application Framework powered by [minimist](https://www.npmjs.com/package/minimist), but with fully strong [TypeScript](https://www.typescriptlang.org/) support.
6
6
 
7
7
  ## Installation
8
8
 
@@ -12,24 +12,51 @@ npm i breadc
12
12
 
13
13
  ## Usage
14
14
 
15
+ Try [./examples/echo.ts](./examples/echo.ts).
16
+
15
17
  ```ts
16
18
  import Breadc from 'breadc'
17
19
 
18
- const cli = Breadc('vite', { version: '1.0.0' })
20
+ const cli = Breadc('echo', { version: '1.0.0' })
19
21
  .option('--host <host>')
20
22
  .option('--port <port>')
21
23
 
22
- cli.command('dev')
23
- .action((option) => {
24
- console.log(`Host: ${option.host}`);
25
- console.log(`Port: ${option.port}`);
24
+ cli
25
+ .command('[message]')
26
+ .action((message, option) => {
27
+ const host = option.host;
28
+ const port = option.port;
29
+ console.log(`Host: ${host}`);
30
+ console.log(`Port: ${port}`);
26
31
  })
27
32
 
28
33
  cli.run(process.argv.slice(2))
29
34
  .catch(err => cli.logger.error(err.message))
30
35
  ```
31
36
 
32
- If you are using IDEs that support TypeScript (like [Visual Studio Code](https://code.visualstudio.com/)), move your cursor to the parameter `option` in this `dev` command, and then you will find the `option` is automatically typed with `{ host: string, port: string }` or `Record<'host' | 'port', string>`.
37
+ If you are using IDEs that support TypeScript (like [Visual Studio Code](https://code.visualstudio.com/)), move your cursor to the parameter `option` in the default command, and then you will find the `option` is automatically typed with `{ host: string | boolean, port: string | boolean }`.
38
+
39
+ ![vscode](./images/vscode.png)
40
+
41
+ ### Limitation
42
+
43
+ For the limitation of TypeScript, in the command format string, you can only write up to **5** pieces. That is to say, you can only write format string like `<p1> <p2> <p3> <p4> [p5]`, but `<p1> <p2> <p3> <p4> <p5> [p6]` does not work.
44
+
45
+ You should always use method chaining when registering options and commands. The example below will fail to infer the option `--host`.
46
+
47
+ ```ts
48
+ const cli = Breadc('cli')
49
+
50
+ cli
51
+ .option('--host')
52
+
53
+ cli
54
+ .option('--port')
55
+ .command('')
56
+ .action((option) => {
57
+ // The type of option is Record<'port', string>
58
+ })
59
+ ```
33
60
 
34
61
  ## Inspiration
35
62