Skip to content

Commit a6ba7be

Browse files
committed
feat(rstack): add help for Rspress commands
1 parent 526159a commit a6ba7be

3 files changed

Lines changed: 176 additions & 0 deletions

File tree

‎packages/rstack/src/cli/commands.ts‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,86 @@ const renderPreviewHelp = (): string =>
110110
],
111111
});
112112

113+
const renderDocHelp = (): string =>
114+
renderHelp({
115+
usage: 'rs doc [command] [root] [options]',
116+
sections: [
117+
{
118+
title: 'Commands',
119+
items: [
120+
['[root]', 'Run the docs dev server (default)'],
121+
['build [root]', 'Build docs for production'],
122+
['preview [root]', 'Preview the docs production build'],
123+
['eject [component]', 'Eject a theme component'],
124+
],
125+
},
126+
{
127+
content: `For command-specific options, run:
128+
$ rs doc <command> -h`,
129+
dim: true,
130+
},
131+
{
132+
title: 'Options',
133+
items: [
134+
['--port <port>', 'Set the port number for the server'],
135+
['--host [host]', 'Set the host that the server listens to'],
136+
['--base <base>', 'Set the base path and override config.base'],
137+
['-c, --config <path>', 'Specify Rstack config file path'],
138+
['-h, --help', 'Display this help message'],
139+
],
140+
},
141+
],
142+
});
143+
144+
const renderDocBuildHelp = (): string =>
145+
renderHelp({
146+
usage: 'rs doc build [root] [options]',
147+
description: 'Build docs for production',
148+
sections: [
149+
{
150+
title: 'Options',
151+
items: [
152+
['--base <base>', 'Set the base path and override config.base'],
153+
['-c, --config <path>', 'Specify Rstack config file path'],
154+
['-h, --help', 'Display this help message'],
155+
],
156+
},
157+
],
158+
});
159+
160+
const renderDocPreviewHelp = (): string =>
161+
renderHelp({
162+
usage: 'rs doc preview [root] [options]',
163+
description: 'Preview the docs production build',
164+
sections: [
165+
{
166+
title: 'Options',
167+
items: [
168+
['--port <port>', 'Set the port number for the server'],
169+
['--host [host]', 'Set the host that the server listens to'],
170+
['--base <base>', 'Set the base path and override config.base'],
171+
['-c, --config <path>', 'Specify Rstack config file path'],
172+
['-h, --help', 'Display this help message'],
173+
],
174+
},
175+
],
176+
});
177+
178+
const renderDocEjectHelp = (): string =>
179+
renderHelp({
180+
usage: 'rs doc eject [component] [options]',
181+
description: 'Eject a theme component',
182+
sections: [
183+
{
184+
title: 'Options',
185+
items: [
186+
['-c, --config <path>', 'Specify Rstack config file path'],
187+
['-h, --help', 'Display this help message'],
188+
],
189+
},
190+
],
191+
});
192+
113193
const renderTestHelp = (): string =>
114194
renderHelp({
115195
usage: 'rs test [command] [...filters] [options]',
@@ -443,6 +523,23 @@ const isMissingRspressCoreError = (error: unknown): boolean => {
443523
};
444524

445525
async function runRspressCLI(args: string[]): Promise<void> {
526+
if (hasHelpFlag(args)) {
527+
switch (args[0]) {
528+
case 'build':
529+
console.log(renderDocBuildHelp());
530+
return;
531+
case 'preview':
532+
console.log(renderDocPreviewHelp());
533+
return;
534+
case 'eject':
535+
console.log(renderDocEjectHelp());
536+
return;
537+
default:
538+
console.log(renderDocHelp());
539+
return;
540+
}
541+
}
542+
446543
const argv = [
447544
process.execPath,
448545
'rspress',

‎packages/rstack/tests/cli/__snapshots__/help.test.ts.snap‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,76 @@ Options:
3535
"
3636
`;
3737
38+
exports[`displays doc build help 1`] = `
39+
"Rstack v<version>
40+
41+
Usage:
42+
$ rs doc build [root] [options]
43+
44+
Build docs for production
45+
46+
Options:
47+
--base <base> Set the base path and override config.base
48+
-c, --config <path> Specify Rstack config file path
49+
-h, --help Display this help message
50+
"
51+
`;
52+
53+
exports[`displays doc eject help 1`] = `
54+
"Rstack v<version>
55+
56+
Usage:
57+
$ rs doc eject [component] [options]
58+
59+
Eject a theme component
60+
61+
Options:
62+
-c, --config <path> Specify Rstack config file path
63+
-h, --help Display this help message
64+
"
65+
`;
66+
67+
exports[`displays doc help 1`] = `
68+
"Rstack v<version>
69+
70+
Usage:
71+
$ rs doc [command] [root] [options]
72+
73+
Commands:
74+
[root] Run the docs dev server (default)
75+
build [root] Build docs for production
76+
preview [root] Preview the docs production build
77+
eject [component] Eject a theme component
78+
79+
For command-specific options, run:
80+
$ rs doc <command> -h
81+
82+
Options:
83+
--port <port> Set the port number for the server
84+
--host [host] Set the host that the server listens to
85+
--base <base> Set the base path and override config.base
86+
-c, --config <path> Specify Rstack config file path
87+
-h, --help Display this help message
88+
"
89+
`;
90+
91+
exports[`displays doc preview help 1`] = `
92+
"Rstack v<version>
93+
94+
Usage:
95+
$ rs doc preview [root] [options]
96+
97+
Preview the docs production build
98+
99+
Options:
100+
--port <port> Set the port number for the server
101+
--host [host] Set the host that the server listens to
102+
--base <base> Set the base path and override config.base
103+
-c, --config <path> Specify Rstack config file path
104+
-h, --help Display this help message
105+
"
106+
`;
107+
38108
exports[`displays lib build help 1`] = `
39109
"Rstack v<version>
40110

‎packages/rstack/tests/cli/help.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ for (const command of ['lib', 'lib build', 'lib inspect', 'lib mf-dev']) {
3030
});
3131
}
3232

33+
for (const command of ['doc', 'doc build', 'doc preview', 'doc eject']) {
34+
test(`displays ${command} help`, ({ execCli, expect }) => {
35+
const output = execCli(`${command} --help`);
36+
37+
expect(execCli(`${command} -h`)).toBe(output);
38+
expect(normalizeHelpOutput(output)).toMatchSnapshot();
39+
});
40+
}
41+
3342
for (const command of [
3443
'test',
3544
'test run',

0 commit comments

Comments
 (0)