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',