Skip to content

Commit 8a8d854

Browse files
author
Anders Brams
committed
Updated README
1 parent 161a049 commit 8a8d854

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,26 @@ new CliCommand('build')
586586
}})
587587
```
588588
589+
#### Call order of onProcess() hooks
590+
The `onProcess()` hooks are called strictly in the order they are assigned to a command, regardless of whether they are assigned on arguments or options.
591+
This is useful for handling inter-dependencies between `onProcess()` calls. For example:
592+
593+
```typescript
594+
await new CliCommand('call-order')
595+
.withOptions({ name: ['-f', '--first'], onProcess: (value) => { console.log(`--first with value ${value}`) } })
596+
.withArguments({ name: 'second', onProcess: (value) => { console.log(`second with value: ${value}`) } })
597+
.withOptions({ name: ['-t', '--third'], onProcess: (value) => { console.log(`--third with value ${value}`) } })
598+
.withHandler(() => { })
599+
```
600+
601+
```bash
602+
$ call-order "This should be second" --first
603+
604+
--first with value true
605+
second with value This should be second
606+
--third with value undefined
607+
```
608+
589609
## Generating documentation
590610
The `CliCommand.dump()` method dumps the entire command (and its subcommands) to an easily readable object of type `CommandDefinition`. This is useful for generating documentation.
591611

0 commit comments

Comments
 (0)