11---
2- title : Inspectors
2+ title : Interceptors
33---
44
5- # Inspectors
5+ # Interceptors
66
7- An inspector is a function that runs before or after calling the command handler, like middleware in koa.
7+ An interceptor is a function that runs before or after calling the command handler, like middleware in koa.
88
99## Usage
1010
11- Inspectors are added to the cli using the ` inspector ` method:
11+ Interceptors are added to the cli using the ` interceptor ` method:
1212
1313``` ts
1414import { Clerc } from " clerc" ;
@@ -18,7 +18,7 @@ const cli = Clerc.create()
1818 .description (" A simple cli" )
1919 .version (" 1.0.0" )
2020 .command (" foo" , " A foo command" )
21- .inspector ((context , next ) => {
21+ .interceptor ((context , next ) => {
2222 console .log (" Before foo" );
2323 // You can inject something into the context, or modify the context
2424 context .foo = " bar" ;
@@ -29,7 +29,7 @@ const cli = Clerc.create()
2929
3030## Order
3131
32- The inspector method accepts either a function or an object:
32+ The interceptor method accepts either a function or an object:
3333
3434``` ts
3535import { Clerc } from " clerc" ;
@@ -39,7 +39,7 @@ const cli = Clerc.create()
3939 .description (" A simple cli" )
4040 .version (" 1.0.0" )
4141 .command (" foo" , " A foo command" )
42- .inspector ({
42+ .interceptor ({
4343 enforce: " normal" , // default, or 'pre', 'post'
4444 fn : (context , next ) => {
4545 console .log (" Before foo" );
@@ -53,9 +53,9 @@ const cli = Clerc.create()
5353
5454So the order of execution is:
5555
56- 1 . Pre inspectors
57- 2 . Normal inspectors
58- 3 . Post inspectors
56+ 1 . Pre interceptors
57+ 2 . Normal interceptors
58+ 3 . Post interceptors
5959
6060## Call after command handler
6161
@@ -69,7 +69,7 @@ const cli = Clerc.create()
6969 .description (" A simple cli" )
7070 .version (" 1.0.0" )
7171 .command (" foo" , " A foo command" )
72- .inspector ((context , next ) => {
72+ .interceptor ((context , next ) => {
7373 console .log (" Before foo" );
7474 // You can inject something into the context, or modify the context
7575 context .foo = " bar" ;
0 commit comments