breadc 0.1.1 → 0.4.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,13 @@
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
+
7
+ ## Features
8
+
9
+ + ⚡️ **Light-weight**: Only 61 kB.
10
+ + 📖 **East to Learn**: Breadc is basically compatible with [cac](https://github.com/cacjs/cac) and there are only 4 APIs for building a CLI application: `command`, `option`, `action`, `run`.
11
+ + 💻 **TypeScript Infer**: IDE will automatically infer the type of your command action function.
6
12
 
7
13
  ## Installation
8
14
 
@@ -12,36 +18,35 @@ npm i breadc
12
18
 
13
19
  ## Usage
14
20
 
15
- See [./examples/echo.ts](./examples/echo.ts).
21
+ Try [./examples/echo.ts](./examples/echo.ts).
16
22
 
17
23
  ```ts
18
24
  import Breadc from 'breadc'
19
25
 
20
26
  const cli = Breadc('echo', { version: '1.0.0' })
21
- .option('--host <host>')
22
- .option('--port <port>')
27
+ .option('--host <host>', { default: 'localhost' })
28
+ .option('--port <port>', { construct: (port) => (port ? +port : 3000) });
23
29
 
24
30
  cli
25
- .command('[message]')
31
+ .command('[message]', 'Say something!')
26
32
  .action((message, option) => {
27
- console.log(message ?? 'You can say anything!')
28
- console.log(`Host: ${option.host}`)
29
- console.log(`Port: ${option.port}`)
33
+ const host = option.host;
34
+ const port = option.port;
35
+ console.log(`Host: ${host}`);
36
+ console.log(`Port: ${port}`);
30
37
  })
31
38
 
32
39
  cli.run(process.argv.slice(2))
33
40
  .catch(err => cli.logger.error(err.message))
34
41
  ```
35
42
 
36
- 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
-
38
- ![vscode1](./images/vscode1.png)
43
+ 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 }`.
39
44
 
40
- ![vscode2](./images/vscode2.png)
45
+ ![vscode](./images/vscode.png)
41
46
 
42
47
  ### Limitation
43
48
 
44
- For the limitation of TypeScript, in the command format string, you can only write up to **4** pieces. That is to say, you can only write format string like `<p1> <p2> <p3> <p4>`, but `<p1> <p2> <p3> <p4> <p5>` does not work.
49
+ 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.
45
50
 
46
51
  You should always use method chaining when registering options and commands. The example below will fail to infer the option `--host`.
47
52