Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/playground/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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);
9 changes: 7 additions & 2 deletions packages/playground/cli/src/run-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command> [options]')
.positional('command', {
describe: 'Command to run',
Expand Down