Skip to content

Commit

Permalink
docs: inspector -> interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Apr 16, 2024
1 parent 34ca1fb commit d8cffb3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const enConfig = defineConfig({
link: "/commands",
},
{
text: "Inspectors",
link: "/inspectors",
text: "Interceptors",
link: "/interceptors",
},
{
text: "Plugins",
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/config/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const zhConfig = defineConfig({
},
{
text: "检查器",
link: "/zh/inspectors",
link: "/zh/interceptors",
},
{
text: "插件",
Expand Down
22 changes: 11 additions & 11 deletions docs/inspectors.md → docs/interceptors.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: Inspectors
title: Interceptors
---

# Inspectors
# Interceptors

An inspector is a function that runs before or after calling the command handler, like middleware in koa.
An interceptor is a function that runs before or after calling the command handler, like middleware in koa.

## Usage

Inspectors are added to the cli using the `inspector` method:
Interceptors are added to the cli using the `interceptor` method:

```ts
import { Clerc } from "clerc";
Expand All @@ -18,7 +18,7 @@ const cli = Clerc.create()
.description("A simple cli")
.version("1.0.0")
.command("foo", "A foo command")
.inspector((context, next) => {
.interceptor((context, next) => {
console.log("Before foo");
// You can inject something into the context, or modify the context
context.foo = "bar";
Expand All @@ -29,7 +29,7 @@ const cli = Clerc.create()

## Order

The inspector method accepts either a function or an object:
The interceptor method accepts either a function or an object:

```ts
import { Clerc } from "clerc";
Expand All @@ -39,7 +39,7 @@ const cli = Clerc.create()
.description("A simple cli")
.version("1.0.0")
.command("foo", "A foo command")
.inspector({
.interceptor({
enforce: "normal", // default, or 'pre', 'post'
fn: (context, next) => {
console.log("Before foo");
Expand All @@ -53,9 +53,9 @@ const cli = Clerc.create()

So the order of execution is:

1. Pre inspectors
2. Normal inspectors
3. Post inspectors
1. Pre interceptors
2. Normal interceptors
3. Post interceptors

## Call after command handler

Expand All @@ -69,7 +69,7 @@ const cli = Clerc.create()
.description("A simple cli")
.version("1.0.0")
.command("foo", "A foo command")
.inspector((context, next) => {
.interceptor((context, next) => {
console.log("Before foo");
// You can inject something into the context, or modify the context
context.foo = "bar";
Expand Down
16 changes: 8 additions & 8 deletions docs/zh/inspectors.md → docs/zh/interceptors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: 检查器

## 用法

可以使用 `inspector` 方法将检查器添加到命令行界面 (CLI) 中:
可以使用 `interceptor` 方法将检查器添加到命令行界面 (CLI) 中:

```ts
import { Clerc } from "clerc";
Expand All @@ -18,7 +18,7 @@ const cli = Clerc.create()
.description("一个简单的命令行界面")
.version("1.0.0")
.command("foo", "一个 foo 命令")
.inspector((context, next) => {
.interceptor((context, next) => {
console.log("在 foo 之前");
// 您可以向上下文中添加一些内容,或修改上下文
context.foo = "bar";
Expand All @@ -29,7 +29,7 @@ const cli = Clerc.create()

## 顺序

`inspector` 方法接受一个函数或一个对象:
`interceptor` 方法接受一个函数或一个对象:

```ts
import { Clerc } from "clerc";
Expand All @@ -39,7 +39,7 @@ const cli = Clerc.create()
.description("一个简单的命令行界面")
.version("1.0.0")
.command("foo", "一个 foo 命令")
.inspector({
.interceptor({
enforce: "normal", // 默认值,或者 'pre', 'post'
fn: (context, next) => {
console.log("在 foo 之前");
Expand All @@ -53,9 +53,9 @@ const cli = Clerc.create()

因此,执行顺序如下:

1. 预检查器(Pre inspectors
2. 正常检查器(Normal inspectors
3. 后检查器(Post inspectors
1. 预检查器(Pre interceptors
2. 正常检查器(Normal interceptors
3. 后检查器(Post interceptors

## 在命令处理程序之后调用

Expand All @@ -69,7 +69,7 @@ const cli = Clerc.create()
.description("一个简单的命令行界面")
.version("1.0.0")
.command("foo", "一个 foo 命令")
.inspector((context, next) => {
.interceptor((context, next) => {
console.log("在 foo 之前");
// 您可以向上下文中添加一些内容,或修改上下文
context.foo = "bar";
Expand Down

0 comments on commit d8cffb3

Please sign in to comment.