breadc 0.6.6 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 XLor
3
+ Copyright (c) 2023 XLor
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # Breadc
2
2
 
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)
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) [![codecov](https://codecov.io/gh/yjl9903/Breadc/branch/main/graph/badge.svg?token=F7PGOG62EF)](https://codecov.io/gh/yjl9903/Breadc)
4
4
 
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.
5
+ Yet another Command Line Application Framework with fully strong **[TypeScript](https://www.typescriptlang.org/) support**.
6
+
7
+ ![vscode](./images/vscode.png)
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: `Breadc`, `command`, `option`, `action`, `run`.
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 Breadc from 'breadc'
26
+ import breadc from 'breadc'
25
27
 
26
- const cli = Breadc('echo', { version: '1.0.0' })
27
- .option('--host [host]', { default: 'localhost' })
28
- .option('--port [port]', { construct: (port) => (port ? +port : 3000) });
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 Record<'port', string>
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 © 2021 [XLor](https://github.com/yjl9903)
75
+ MIT License © 2023 [XLor](https://github.com/yjl9903)