Skip to content

🎥 Make videos programmatically with React

`@remotion/cli`: Show command-specific documentation for `--help`

JonnyBurger9c8b8ccec1ee
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts
index e66991c5a1..4beffb8197 100644
--- a/packages/cli/src/index.ts
+++ b/packages/cli/src/index.ts
@@ -58,6 +58,10 @@ const {packageManagerOption, skipSkillsOption, versionFlagOption} =
export const cli = async () => {
const [command, ...args] = parsedCli._;
+ if (parsedCli.help) {
+ printHelp('info', command ?? null);
+ return;
+ }
const packageManager = packageManagerOption.getValue({
commandLine: parsedCli,
@@ -161,16 +165,14 @@ export const cli = async () => {
} else if (command === 'benchmark') {
await benchmarkCommand(remotionRoot, args, logLevel);
} else if (command === 'help') {
- printHelp(logLevel);
+ printHelp(logLevel, null);
process.exit(0);
- } else if (parsedCli.help) {
- printHelp(logLevel);
} else {
if (command) {
Log.error({indent: false, logLevel}, `Command ${command} not found.`);
}
- printHelp(logLevel);
+ printHelp(logLevel, null);
process.exit(1);
}
} catch (err) {
diff --git a/packages/cli/src/print-help.ts b/packages/cli/src/print-help.ts
index 2d9e68c1f9..c177f83ba6 100644
--- a/packages/cli/src/print-help.ts
+++ b/packages/cli/src/print-help.ts
@@ -7,169 +7,188 @@ import {VERSIONS_COMMAND} from './versions';
const packagejson = require('../package.json');
-export const printHelp = (logLevel: LogLevel) => {
- Log.info({indent: false, logLevel}, `@remotion/cli ${packagejson.version}`);
- Log.info(
- {indent: false, logLevel},
- `© ${new Date().getFullYear()} Remotion AG`,
- );
- Log.info({indent: false, logLevel});
- Log.info({indent: false, logLevel}, 'Available commands:');
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion studio') + chalk.gray(' <entry-point.ts>'),
- );
- Log.info({indent: false, logLevel}, 'Start the Remotion studio.');
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/studio'),
- );
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion render') +
- chalk.gray(' <entry-point.ts> <comp-id> <output-file.mp4>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Render video, audio or an image sequence.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/render'),
- );
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion still') +
- chalk.gray(' <entry-point.ts> <comp-id> <still.png>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Render a still frame and save it as an image.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/still'),
- );
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion bundle') + chalk.gray(' <entry-point.ts>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Create a Remotion bundle to be deployed to the web.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/bundle'),
- );
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion compositions') + chalk.gray(' <index-file.ts>'),
- );
- Log.info({indent: false, logLevel}, 'Prints the available compositions.');
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/compositions'),
- );
-
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion benchmark') +
- chalk.gray(' <index-file.ts> <list-of-compositions>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Benchmarks rendering a composition. Same options as for render.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/benchmark'),
- );
+type CommandHelp = {
+ name: string;
+ aliases: readonly string[];
+ args: string;
+ description: string;
+ documentation: string;
+};
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion ' + VERSIONS_COMMAND),
- );
- Log.info(
- {indent: false, logLevel},
- 'Prints and validates versions of all Remotion packages.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/versions'),
- );
+const commandHelp: readonly CommandHelp[] = [
+ {
+ name: 'studio',
+ aliases: ['preview'],
+ args: ' <entry-point>?',
+ description: 'Start the Remotion Studio.',
+ documentation: 'https://www.remotion.dev/docs/cli/studio',
+ },
+ {
+ name: 'render',
+ aliases: [],
+ args: ' <entry-point|serve-url>? <composition-id> <output-location>',
+ description: 'Render video, audio or an image sequence.',
+ documentation: 'https://www.remotion.dev/docs/cli/render',
+ },
+ {
+ name: 'still',
+ aliases: [],
+ args: ' <serve-url|entry-point>? [<composition-id>] [<output-location>]',
+ description: 'Render a still frame and save it as an image.',
+ documentation: 'https://www.remotion.dev/docs/cli/still',
+ },
+ {
+ name: 'compositions',
+ aliases: [],
+ args: ' <serve-url|entry-file>?',
+ description: 'Prints the available compositions.',
+ documentation: 'https://www.remotion.dev/docs/cli/compositions',
+ },
+ {
+ name: 'lambda',
+ aliases: [],
+ args: ' <command>',
+ description: 'Control Remotion Lambda.',
+ documentation: 'https://www.remotion.dev/docs/lambda/cli',
+ },
+ {
+ name: 'bundle',
+ aliases: [],
+ args: ' <serve-url|entry-file>?',
+ description: 'Create a Remotion bundle to be deployed to the web.',
+ documentation: 'https://www.remotion.dev/docs/cli/bundle',
+ },
+ {
+ name: BROWSER_COMMAND,
+ aliases: [],
+ args: ' <command>',
+ description: 'Ensure Remotion has a browser it can use for rendering.',
+ documentation: 'https://www.remotion.dev/docs/cli/browser',
+ },
+ {
+ name: 'cloudrun',
+ aliases: [],
+ args: ' <command>',
+ description: 'Control Remotion Cloud Run.',
+ documentation: 'https://www.remotion.dev/docs/cloudrun/cli',
+ },
+ {
+ name: 'benchmark',
+ aliases: [],
+ args: ' <entry-point> [composition-ids]',
+ description:
+ 'Benchmarks rendering a composition. Same options as for render.',
+ documentation: 'https://www.remotion.dev/docs/cli/benchmark',
+ },
+ {
+ name: 'skills',
+ aliases: [],
+ args: ' <add | update>',
+ description: 'Install or update skills from remotion-dev/skills.',
+ documentation: 'https://www.remotion.dev/docs/cli/skills',
+ },
+ {
+ name: VERSIONS_COMMAND,
+ aliases: [],
+ args: '',
+ description: 'Prints and validates versions of all Remotion packages.',
+ documentation: 'https://www.remotion.dev/docs/cli/versions',
+ },
+ {
+ name: 'upgrade',
+ aliases: [],
+ args: '',
+ description: 'Ensure Remotion is on the newest version.',
+ documentation: 'https://www.remotion.dev/docs/cli/upgrade',
+ },
+ {
+ name: 'add',
+ aliases: [],
+ args: ' <package-name...>',
+ description: 'Add Remotion packages with the correct version.',
+ documentation: 'https://www.remotion.dev/docs/cli/add',
+ },
+ {
+ name: GPU_COMMAND,
+ aliases: [],
+ args: '',
+ description: 'Prints information about how Chrome uses the GPU.',
+ documentation: 'https://www.remotion.dev/docs/cli/gpu',
+ },
+ {
+ name: 'ffmpeg',
+ aliases: [],
+ args: ' <arguments...>',
+ description: 'Execute an FFmpeg command.',
+ documentation: 'https://www.remotion.dev/docs/cli/ffmpeg',
+ },
+ {
+ name: 'ffprobe',
+ aliases: [],
+ args: ' <arguments...>',
+ description: 'Execute an FFprobe command.',
+ documentation: 'https://www.remotion.dev/docs/cli/ffprobe',
+ },
+ {
+ name: 'help',
+ aliases: [],
+ args: '',
+ description: 'Print available commands and flags for the Remotion CLI.',
+ documentation: 'https://www.remotion.dev/docs/cli/help',
+ },
+];
- Log.info({indent: false, logLevel});
- Log.info({indent: false, logLevel}, chalk.blue('remotion ' + GPU_COMMAND));
- Log.info(
- {indent: false, logLevel},
- 'Prints information about how Chrome uses the CPU.',
- );
+const printCommandHelp = ({
+ command,
+ displayName,
+ logLevel,
+}: {
+ command: CommandHelp;
+ displayName: string;
+ logLevel: LogLevel;
+}) => {
Log.info(
{indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/gpu'),
+ chalk.blue(`remotion ${displayName}`) + chalk.gray(command.args),
);
+ Log.info({indent: false, logLevel}, command.description);
+ Log.info({indent: false, logLevel}, chalk.gray(command.documentation));
+};
- Log.info({indent: false, logLevel});
- Log.info({indent: false, logLevel}, chalk.blue('remotion upgrade'));
- Log.info(
- {indent: false, logLevel},
- 'Ensure Remotion is on the newest version.',
- );
+export const printHelp = (
+ logLevel: LogLevel,
+ selectedCommand: string | null,
+) => {
+ Log.info({indent: false, logLevel}, `@remotion/cli ${packagejson.version}`);
Log.info(
{indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/upgrade'),
+ `© ${new Date().getFullYear()} Remotion AG`,
);
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion add') + chalk.gray(' <package-name...>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Add Remotion packages with the correct version.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/add'),
- );
+ if (selectedCommand !== null) {
+ const selectedCommandHelp = commandHelp.find(
+ (command) =>
+ command.name === selectedCommand ||
+ command.aliases.includes(selectedCommand),
+ );
+ if (selectedCommandHelp) {
+ Log.info({indent: false, logLevel});
+ printCommandHelp({
+ command: selectedCommandHelp,
+ displayName: selectedCommand,
+ logLevel,
+ });
+ return;
+ }
+ }
Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue('remotion skills ') + chalk.gray('<add | update>'),
- );
- Log.info(
- {indent: false, logLevel},
- 'Install or update skills from remotion-dev/skills.',
- );
+ Log.info({indent: false, logLevel}, 'Available commands:');
- Log.info({indent: false, logLevel});
- Log.info(
- {indent: false, logLevel},
- chalk.blue(`remotion ${BROWSER_COMMAND}`),
- );
- Log.info(
- {indent: false, logLevel},
- 'Ensure Remotion has a browser it can use for rendering.',
- );
- Log.info(
- {indent: false, logLevel},
- chalk.gray('https://www.remotion.dev/docs/cli/browser'),
- );
+ for (const command of commandHelp) {
+ Log.info({indent: false, logLevel});
+ printCommandHelp({command, displayName: command.name, logLevel});
+ }
Log.info({indent: false, logLevel});
Log.info(
diff --git a/packages/cli/src/test/help.test.ts b/packages/cli/src/test/help.test.ts
new file mode 100644
index 0000000000..8211e866ed
--- /dev/null
+++ b/packages/cli/src/test/help.test.ts
@@ -0,0 +1,75 @@
+import {expect, test} from 'bun:test';
+import {spawnSync} from 'node:child_process';
+import {mkdtempSync, readdirSync, rmSync, writeFileSync} from 'node:fs';
+import {tmpdir} from 'node:os';
+import path from 'node:path';
+
+const cliPath = path.join(__dirname, '..', '..', 'remotion-cli.js');
+
+const commandHelpPages = [
+ {args: ['render'], documentation: '/docs/cli/render'},
+ {args: ['studio'], documentation: '/docs/cli/studio'},
+ {args: ['preview'], documentation: '/docs/cli/studio'},
+ {args: ['still'], documentation: '/docs/cli/still'},
+ {args: ['compositions'], documentation: '/docs/cli/compositions'},
+ {args: ['lambda'], documentation: '/docs/lambda/cli'},
+ {args: ['bundle'], documentation: '/docs/cli/bundle'},
+ {args: ['browser'], documentation: '/docs/cli/browser'},
+ {args: ['browser', 'ensure'], documentation: '/docs/cli/browser'},
+ {args: ['cloudrun'], documentation: '/docs/cloudrun/cli'},
+ {args: ['benchmark'], documentation: '/docs/cli/benchmark'},
+ {args: ['skills'], documentation: '/docs/cli/skills'},
+ {args: ['skills', 'add'], documentation: '/docs/cli/skills'},
+ {args: ['skills', 'update'], documentation: '/docs/cli/skills'},
+ {args: ['versions'], documentation: '/docs/cli/versions'},
+ {args: ['upgrade'], documentation: '/docs/cli/upgrade'},
+ {args: ['add'], documentation: '/docs/cli/add'},
+ {args: ['gpu'], documentation: '/docs/cli/gpu'},
+ {args: ['ffmpeg'], documentation: '/docs/cli/ffmpeg'},
+ {args: ['ffprobe'], documentation: '/docs/cli/ffprobe'},
+ {args: ['help'], documentation: '/docs/cli/help'},
+] as const;
+
+test('prints command-specific help without running the command', () => {
+ const temporaryDirectory = mkdtempSync(
+ path.join(tmpdir(), 'remotion-cli-help-'),
+ );
+ writeFileSync(
+ path.join(temporaryDirectory, 'remotion.config.ts'),
+ `throw new Error('The config file must not be loaded for --help');\n`,
+ );
+ const initialFiles = readdirSync(temporaryDirectory);
+
+ try {
+ for (const {args, documentation} of commandHelpPages) {
+ const result = spawnSync(
+ 'node',
+ [cliPath, ...args, '--help', '--log=error'],
+ {
+ cwd: temporaryDirectory,
+ encoding: 'utf8',
+ env: {...process.env, NO_COLOR: '1'},
+ stdio: ['ignore', 'pipe', 'pipe'],
+ timeout: 10_000,
+ },
+ );
+
+ if (result.error) {
+ throw result.error;
+ }
+
+ expect(result.signal).toBeNull();
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe('');
+ expect(result.stdout).toContain(`remotion ${args[0]}`);
+ expect(result.stdout).toContain(
+ `https://www.remotion.dev${documentation}`,
+ );
+ expect(result.stdout).not.toContain('Available commands:');
+ }
+
+ expect(readdirSync(temporaryDirectory)).toEqual(initialFiles);
+ } finally {
+ rmSync(temporaryDirectory, {recursive: true, force: true});
+ }
+}, 30_000);