add-cli-option
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd a new CLI option
添加新的CLI选项
How to convert a hardcoded CLI flag into a proper , or add a brand new one.
AnyRemotionOption如何将硬编码的CLI标志转换为标准的,或者添加一个全新的选项。
AnyRemotionOption1. Create the option definition
1. 创建选项定义
Create :
packages/renderer/src/options/<name>.tsxtsx
import type {AnyRemotionOption} from './option';
let myValue = false; // module-level default state
const cliFlag = 'my-flag' as const;
export const myFlagOption = {
name: 'Human-readable Name',
cliFlag,
description: () => <>Description shown in docs.</>,
ssrName: null, // or 'myFlag' if used in SSR APIs
docLink: 'https://www.remotion.dev/docs/config#setmyflagenabled',
type: false as boolean, // default value, also sets the TypeScript type
getValue: ({commandLine}) => {
if (commandLine[cliFlag] !== undefined) {
return {value: commandLine[cliFlag] as boolean, source: 'cli'};
}
return {value: myValue, source: 'config'};
},
setConfig(value) {
myValue = value;
},
} satisfies AnyRemotionOption<boolean>;The type in and determines the option's value type. Use , , , etc.
AnyRemotionOption<T>type: <default> as Tbooleanstring | nullnumber | nullFor negating flags (like → ), handle the inversion in .
--disable-ask-aiaskAIEnabled = falsegetValue在中创建文件:
packages/renderer/src/options/<name>.tsxtsx
import type {AnyRemotionOption} from './option';
let myValue = false; // module-level default state
const cliFlag = 'my-flag' as const;
export const myFlagOption = {
name: 'Human-readable Name',
cliFlag,
description: () => <>Description shown in docs.</>,
ssrName: null, // or 'myFlag' if used in SSR APIs
docLink: 'https://www.remotion.dev/docs/config#setmyflagenabled',
type: false as boolean, // default value, also sets the TypeScript type
getValue: ({commandLine}) => {
if (commandLine[cliFlag] !== undefined) {
return {value: commandLine[cliFlag] as boolean, source: 'cli'};
}
return {value: myValue, source: 'config'};
},
setConfig(value) {
myValue = value;
},
} satisfies AnyRemotionOption<boolean>;AnyRemotionOption<T>type: <default> as Tbooleanstring | nullnumber | null对于否定式标志(如 → ),需在中处理反转逻辑。
--disable-ask-aiaskAIEnabled = falsegetValue2. Register in options index
2. 在选项索引中注册
packages/renderer/src/options/index.tsx- Add the import (keep alphabetical within the import block)
- Add the option to the object
allOptions
This makes it available as throughout the codebase.
BrowserSafeApis.options.myFlagOptionpackages/renderer/src/options/index.tsx- 添加导入语句(在导入块内按字母顺序排列)
- 将选项添加到对象中
allOptions
此操作会让该选项在整个代码库中可通过访问。
BrowserSafeApis.options.myFlagOption3. Update CLI parsed flags
3. 更新CLI解析标志
packages/cli/src/parsed-cli.ts- For boolean flags, add to the
BrowserSafeApis.options.myFlagOption.cliFlagarrayBooleanFlags - For non-boolean flags, no entry needed here (minimist handles them as strings/numbers automatically)
packages/cli/src/parse-command-line.ts- Add to the destructured
BrowserSafeApis.options - In the type, add:
CommandLineOptions[myFlagOption.cliFlag]: TypeOfOption<typeof myFlagOption>;
packages/cli/src/parsed-cli.ts- 对于布尔型标志,将添加到
BrowserSafeApis.options.myFlagOption.cliFlag数组中BooleanFlags - 对于非布尔型标志,无需在此处添加(minimist会自动将其处理为字符串/数字)
packages/cli/src/parse-command-line.ts- 添加到解构后的中
BrowserSafeApis.options - 在类型中添加:
CommandLineOptions[myFlagOption.cliFlag]: TypeOfOption<typeof myFlagOption>;
4. Use the option where needed
4. 在需要的地方使用选项
Instead of reading directly, resolve via:
parsedCli['my-flag']ts
const myFlag = myFlagOption.getValue({commandLine: parsedCli}).value;For Studio options, this is typically in . For render options, in the relevant render command file.
packages/cli/src/studio.ts不要直接读取,而是通过以下方式获取:
parsedCli['my-flag']ts
const myFlag = myFlagOption.getValue({commandLine: parsedCli}).value;对于Studio选项,通常在中使用。对于渲染选项,在对应的渲染命令文件中使用。
packages/cli/src/studio.ts5. Add to Config
5. 添加到配置中
packages/cli/src/config/index.ts- Add to the destructured
BrowserSafeApis.options - Add the setter signature to the type (either in the
FlatConfigglobal interface or theRemotionConfigObjectintersection)FlatConfig - Add the implementation to the object:
ConfigsetMyFlagEnabled: myFlagOption.setConfig
packages/cli/src/config/index.ts- 添加到解构后的中
BrowserSafeApis.options - 在类型中添加设置器签名(可在全局接口
FlatConfig或RemotionConfigObject交叉类型中添加)FlatConfig - 在对象中添加实现:
ConfigsetMyFlagEnabled: myFlagOption.setConfig
6. Update docs — IMPORTANT, do not skip this step
6. 更新文档——重要,请勿跳过此步骤
This step is mandatory. Every new option must have its docs updated to use so the description is pulled from the option definition automatically (single source of truth). If converting an existing hardcoded flag, replace any hand-written description with the component.
<Options id="..." /><Options>CLI command pages (check all that apply — , , , ):
cli/render.mdxlambda/cli/render.mdxcloudrun/cli/render.mdxcli/benchmark.mdx- Add or update the --my-flag`` section
### \ - Use as the description body (no import needed — it's globally available)
<Options id="my-flag" /> - The must match the option's
id/cliFlagvalueid
packages/docs/docs/config.mdx- Add or update the setMyFlagEnabled()`` section with:
## \- for the description
<Options id="my-flag" /> - A twoslash config example
- A note that the CLI flag takes precedence
Follow the pattern of nearby entries (e.g., , ).
setAskAIEnabledsetEnableCrossSiteIsolation**此步骤为必填项。**每个新选项都必须更新文档,使用组件,以便自动从选项定义中拉取描述(单一数据源)。如果是转换现有硬编码标志,请将手写描述替换为组件。
<Options id="..." /><Options>CLI命令页面(检查所有适用页面——、、、):
cli/render.mdxlambda/cli/render.mdxcloudrun/cli/render.mdxcli/benchmark.mdx- 添加或更新--my-flag``章节
### \ - 使用作为描述主体(无需导入——它是全局可用的)
<Options id="my-flag" /> - 必须与选项的
id/cliFlag值匹配id
packages/docs/docs/config.mdx- 添加或更新setMyFlagEnabled()``章节,包含:
## \- 使用作为描述
<Options id="my-flag" /> - 一个twoslash配置示例
- 说明CLI标志优先级更高的注释
- 使用
遵循附近条目的格式(例如、)。
setAskAIEnabledsetEnableCrossSiteIsolation7. Build and verify
7. 构建并验证
sh
cd packages/renderer && bun run make
cd packages/cli && bun run makesh
cd packages/renderer && bun run make
cd packages/cli && bun run makeReference files
参考文件
- Option type definition:
packages/renderer/src/options/option.ts - Good example to copy: (boolean, studio-only)
packages/renderer/src/options/ask-ai.tsx - Options index:
packages/renderer/src/options/index.tsx - CLI flag registration:
packages/cli/src/parsed-cli.ts - CLI type definitions:
packages/cli/src/parse-command-line.ts - Config registration:
packages/cli/src/config/index.ts
- 选项类型定义:
packages/renderer/src/options/option.ts - 可参考的示例:(布尔型,仅Studio可用)
packages/renderer/src/options/ask-ai.tsx - 选项索引:
packages/renderer/src/options/index.tsx - CLI标志注册:
packages/cli/src/parsed-cli.ts - CLI类型定义:
packages/cli/src/parse-command-line.ts - 配置注册:
packages/cli/src/config/index.ts