Skip to content

Commit fc63ce7

Browse files
committed
Update the cli documentation format for commands
1 parent 5ce5752 commit fc63ce7

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,17 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
8787
*/
8888
const yargsObject = yargs(argsToParse)
8989
.usage('Usage: wp-playground <command> [options]')
90-
.positional('command', {
91-
describe: 'Command to run',
92-
choices: ['server', 'run-blueprint', 'build-snapshot'] as const,
93-
demandOption: true,
94-
})
90+
.command('server', 'Start a local WordPress server')
91+
.command(
92+
'run-blueprint',
93+
'Execute a Blueprint without starting a server'
94+
)
95+
.command(
96+
'build-snapshot',
97+
'Build a ZIP snapshot of a WordPress site based on a Blueprint'
98+
)
99+
.demandCommand(1, 'Please specify a command')
100+
.strictCommands()
95101
.option('outfile', {
96102
describe: 'When building, write to this output file.',
97103
type: 'string',
@@ -287,6 +293,18 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
287293
hidden: true,
288294
})
289295
.showHelpOnFail(false)
296+
.fail((msg, err, yargsInstance) => {
297+
if (err) {
298+
throw err;
299+
}
300+
if (msg && msg.includes('Please specify a command')) {
301+
yargsInstance.showHelp();
302+
console.error('\n' + msg);
303+
process.exit(1);
304+
}
305+
console.error(msg);
306+
process.exit(1);
307+
})
290308
.strictOptions()
291309
.check(async (args) => {
292310
if (args['skip-wordpress-install'] === true) {
@@ -600,6 +618,9 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
600618
logger.setSeverityFilterLevel(severity);
601619
}
602620

621+
const selectedPort =
622+
args.command === 'server' ? (args['port'] as number) ?? 9400 : 0;
623+
603624
// Declare file lock manager outside scope of startServer
604625
// so we can look at it when debugging request handling.
605626
const nativeFlockSync =
@@ -624,7 +645,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
624645
logger.log('Starting a PHP server...');
625646

626647
return startServer({
627-
port: args['port'] as number,
648+
port: selectedPort,
628649
onBind: async (server: Server, port: number) => {
629650
const host = '127.0.0.1';
630651
const serverUrl = `http://${host}:${port}`;

0 commit comments

Comments
 (0)