Skip to content

Commit 8775ba7

Browse files
authored
[CLI] Readable commands help message (#2927)
## Motivation for the change, related issues Formats Playground CLI commands vertically in the CLI help message: <img width="2178" height="1174" alt="CleanShot 2025-11-21 at 17 11 18@2x" src="https://github.com/user-attachments/assets/d84a35ef-e0a6-4c34-b5bb-a066af26716a" /> Before this PR, they were aligned to the right and easy to miss: <img width="2172" height="710" alt="CleanShot 2025-11-21 at 17 12 03@2x" src="https://github.com/user-attachments/assets/5152d424-c8ec-45a4-8ac5-1c0fc3f31145" /> Technically, we use yargs `.command()` instead of `.positional()`. cc @wojtekn
1 parent f6425d1 commit 8775ba7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

packages/playground/cli/src/run-cli.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
8888
*/
8989
const yargsObject = yargs(argsToParse)
9090
.usage('Usage: wp-playground <command> [options]')
91-
.positional('command', {
92-
describe: 'Command to run',
93-
choices: ['server', 'run-blueprint', 'build-snapshot'] as const,
94-
demandOption: true,
95-
})
91+
.command('server', 'Start a local WordPress server')
92+
.command(
93+
'run-blueprint',
94+
'Execute a Blueprint without starting a server'
95+
)
96+
.command(
97+
'build-snapshot',
98+
'Build a ZIP snapshot of a WordPress site based on a Blueprint'
99+
)
100+
.demandCommand(1, 'Please specify a command')
101+
.strictCommands()
96102
.option('outfile', {
97103
describe: 'When building, write to this output file.',
98104
type: 'string',
@@ -288,6 +294,18 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
288294
hidden: true,
289295
})
290296
.showHelpOnFail(false)
297+
.fail((msg, err, yargsInstance) => {
298+
if (err) {
299+
throw err;
300+
}
301+
if (msg && msg.includes('Please specify a command')) {
302+
yargsInstance.showHelp();
303+
console.error('\n' + msg);
304+
process.exit(1);
305+
}
306+
console.error(msg);
307+
process.exit(1);
308+
})
291309
.strictOptions()
292310
.check(async (args) => {
293311
if (args['skip-wordpress-install'] === true) {

0 commit comments

Comments
 (0)