6363## Install
6464
6565``` bash
66- yarn add cac
66+ npm i cac
6767```
6868
6969## Usage
124124 .command (' rm <dir>' , ' Remove a dir' )
125125 .option (' -r, --recursive' , ' Remove recursively' )
126126 .action ((dir , options ) => {
127- console .log (' remove ' + dir + ( options .recursive ? ' recursively' : ' ' ) )
127+ console .log (` remove ${ dir}${ options .recursive ? ' recursively' : ' ' } ` )
128128 })
129129
130130cli .help ()
@@ -280,8 +280,8 @@ try {
280280} catch (error) {
281281 // Handle error here..
282282 // e.g.
283- // console.error(error.stack)
284- // process.exit(1)
283+ console .error (error .stack )
284+ process .exit (1 )
285285}
286286```
287287
@@ -290,14 +290,12 @@ try {
290290First you need ` @types/node ` to be installed as a dev dependency in your project:
291291
292292``` bash
293- yarn add @types/node --dev
293+ npm i @types/node --dev
294294```
295295
296296Then everything just works out of the box:
297297
298298``` js
299- const { cac } = require (' cac' )
300- // OR ES modules
301299import { cac } from ' cac'
302300```
303301
@@ -438,7 +436,7 @@ Use a callback function as the command action when the command matches user inpu
438436type ActionCallback = (
439437 // Parsed CLI args
440438 // The last arg will be an array if it's a variadic argument
441- ... args : string | string [] | number | number []
439+ ... args : string | string [] | number | number [],
442440 // Parsed CLI options
443441 options : Options
444442) => any
@@ -482,17 +480,17 @@ Listen to commands:
482480
483481` ` ` js
484482// Listen to the `foo` command
485- cli .on (' command:foo' , () => {
483+ cli .addEventListener (' command:foo' , () => {
486484 // Do something
487485})
488486
489487// Listen to the default command
490- cli .on (' command:!' , () => {
488+ cli .addEventListener (' command:!' , () => {
491489 // Do something
492490})
493491
494492// Listen to unknown commands
495- cli .on (' command:*' , () => {
493+ cli .addEventListener (' command:*' , () => {
496494 console .error (' Invalid command: %s' , cli .args .join (' ' ))
497495 process .exit (1 )
498496})
0 commit comments