From 1cc20da60faba9f945b7d77a1ef6a8a2b5ad540d Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Tue, 11 Nov 2025 17:31:51 -0500 Subject: [PATCH] [CLI] Expose arg parsing to API consumers This change allows API consumers like WordPress Studio to start Playground CLI with its built-in command line parsing. That way, consumers can use Playground CLI defaults for options like `--experimental-multi-worker` or `--experimental-unsafe-ide-integration` rather than having to provide their own defaults. --- packages/playground/cli/src/cli.ts | 5 ++++- packages/playground/cli/src/run-cli.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/playground/cli/src/cli.ts b/packages/playground/cli/src/cli.ts index 60fc43a78d..a11097e854 100644 --- a/packages/playground/cli/src/cli.ts +++ b/packages/playground/cli/src/cli.ts @@ -1,4 +1,7 @@ import { parseOptionsAndRunCLI } from './run-cli'; +// The CLI args are after the original command and the script name +const args = process.argv.slice(2); + // Do not await this as top-level await is not supported in all environments. -parseOptionsAndRunCLI(); +parseOptionsAndRunCLI(args); diff --git a/packages/playground/cli/src/run-cli.ts b/packages/playground/cli/src/run-cli.ts index 67af7faa01..e4703cb26b 100644 --- a/packages/playground/cli/src/run-cli.ts +++ b/packages/playground/cli/src/run-cli.ts @@ -74,13 +74,18 @@ type LogVerbosity = (typeof LogVerbosity)[keyof typeof LogVerbosity]['name']; export type WorkerType = 'v1' | 'v2'; -export async function parseOptionsAndRunCLI() { +/** + * Parse the CLI args and run the appropriate command. + * + * @param argsToParse string[] The CLI args to parse. + */ +export async function parseOptionsAndRunCLI(argsToParse: string[]) { try { /** * @TODO This looks similar to Query API args https://wordpress.github.io/wordpress-playground/developers/apis/query-api/ * Perhaps the two could be handled by the same code? */ - const yargsObject = yargs(process.argv.slice(2)) + const yargsObject = yargs(argsToParse) .usage('Usage: wp-playground [options]') .positional('command', { describe: 'Command to run',