From d8cffb3331ff03a9e3158334ec24c92f1d7cdf37 Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 16 Apr 2024 12:34:19 +0800 Subject: [PATCH] docs: `inspector` -> `interceptor` --- docs/.vitepress/config/en.ts | 4 ++-- docs/.vitepress/config/zh.ts | 2 +- docs/{inspectors.md => interceptors.md} | 22 +++++++++++----------- docs/zh/{inspectors.md => interceptors.md} | 16 ++++++++-------- 4 files changed, 22 insertions(+), 22 deletions(-) rename docs/{inspectors.md => interceptors.md} (77%) rename docs/zh/{inspectors.md => interceptors.md} (83%) diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 2337cd0..cf768ba 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -32,8 +32,8 @@ export const enConfig = defineConfig({ link: "/commands", }, { - text: "Inspectors", - link: "/inspectors", + text: "Interceptors", + link: "/interceptors", }, { text: "Plugins", diff --git a/docs/.vitepress/config/zh.ts b/docs/.vitepress/config/zh.ts index 8d9b216..d65d555 100644 --- a/docs/.vitepress/config/zh.ts +++ b/docs/.vitepress/config/zh.ts @@ -33,7 +33,7 @@ export const zhConfig = defineConfig({ }, { text: "检查器", - link: "/zh/inspectors", + link: "/zh/interceptors", }, { text: "插件", diff --git a/docs/inspectors.md b/docs/interceptors.md similarity index 77% rename from docs/inspectors.md rename to docs/interceptors.md index 6a96b73..316fb7f 100644 --- a/docs/inspectors.md +++ b/docs/interceptors.md @@ -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"; @@ -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"; @@ -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"; @@ -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"); @@ -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 @@ -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"; diff --git a/docs/zh/inspectors.md b/docs/zh/interceptors.md similarity index 83% rename from docs/zh/inspectors.md rename to docs/zh/interceptors.md index 823357c..d4ebf2f 100644 --- a/docs/zh/inspectors.md +++ b/docs/zh/interceptors.md @@ -8,7 +8,7 @@ title: 检查器 ## 用法 -可以使用 `inspector` 方法将检查器添加到命令行界面 (CLI) 中: +可以使用 `interceptor` 方法将检查器添加到命令行界面 (CLI) 中: ```ts import { Clerc } from "clerc"; @@ -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"; @@ -29,7 +29,7 @@ const cli = Clerc.create() ## 顺序 -`inspector` 方法接受一个函数或一个对象: +`interceptor` 方法接受一个函数或一个对象: ```ts import { Clerc } from "clerc"; @@ -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 之前"); @@ -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) ## 在命令处理程序之后调用 @@ -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";