From fc63ce7b7bcdd3947cca5e115004ae3c8a78b10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 21 Nov 2025 17:11:44 +0100 Subject: [PATCH 1/2] Update the cli documentation format for commands --- packages/playground/cli/src/run-cli.ts | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/playground/cli/src/run-cli.ts b/packages/playground/cli/src/run-cli.ts index 0a79672b13..bfac9b3e0c 100644 --- a/packages/playground/cli/src/run-cli.ts +++ b/packages/playground/cli/src/run-cli.ts @@ -87,11 +87,17 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) { */ const yargsObject = yargs(argsToParse) .usage('Usage: wp-playground [options]') - .positional('command', { - describe: 'Command to run', - choices: ['server', 'run-blueprint', 'build-snapshot'] as const, - demandOption: true, - }) + .command('server', 'Start a local WordPress server') + .command( + 'run-blueprint', + 'Execute a Blueprint without starting a server' + ) + .command( + 'build-snapshot', + 'Build a ZIP snapshot of a WordPress site based on a Blueprint' + ) + .demandCommand(1, 'Please specify a command') + .strictCommands() .option('outfile', { describe: 'When building, write to this output file.', type: 'string', @@ -287,6 +293,18 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) { hidden: true, }) .showHelpOnFail(false) + .fail((msg, err, yargsInstance) => { + if (err) { + throw err; + } + if (msg && msg.includes('Please specify a command')) { + yargsInstance.showHelp(); + console.error('\n' + msg); + process.exit(1); + } + console.error(msg); + process.exit(1); + }) .strictOptions() .check(async (args) => { if (args['skip-wordpress-install'] === true) { @@ -600,6 +618,9 @@ export async function runCLI(args: RunCLIArgs): Promise { logger.setSeverityFilterLevel(severity); } + const selectedPort = + args.command === 'server' ? (args['port'] as number) ?? 9400 : 0; + // Declare file lock manager outside scope of startServer // so we can look at it when debugging request handling. const nativeFlockSync = @@ -624,7 +645,7 @@ export async function runCLI(args: RunCLIArgs): Promise { logger.log('Starting a PHP server...'); return startServer({ - port: args['port'] as number, + port: selectedPort, onBind: async (server: Server, port: number) => { const host = '127.0.0.1'; const serverUrl = `http://${host}:${port}`; From 678ac1b2752ae27033393e8989a303b604d98c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 21 Nov 2025 23:36:16 +0100 Subject: [PATCH 2/2] Restore args["port"] usage --- packages/playground/cli/src/run-cli.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/playground/cli/src/run-cli.ts b/packages/playground/cli/src/run-cli.ts index bfac9b3e0c..bc4774dd73 100644 --- a/packages/playground/cli/src/run-cli.ts +++ b/packages/playground/cli/src/run-cli.ts @@ -618,9 +618,6 @@ export async function runCLI(args: RunCLIArgs): Promise { logger.setSeverityFilterLevel(severity); } - const selectedPort = - args.command === 'server' ? (args['port'] as number) ?? 9400 : 0; - // Declare file lock manager outside scope of startServer // so we can look at it when debugging request handling. const nativeFlockSync = @@ -645,7 +642,7 @@ export async function runCLI(args: RunCLIArgs): Promise { logger.log('Starting a PHP server...'); return startServer({ - port: selectedPort, + port: args['port'] as number, onBind: async (server: Server, port: number) => { const host = '127.0.0.1'; const serverUrl = `http://${host}:${port}`;