Skip to main content

executeServiceCommand

@webda/core


Function: executeServiceCommand()

executeServiceCommand(cmdName, cmdInfo, args, services, serviceFilter?): Promise<number>

Defined in: packages/core/src/services/servicecommands.ts:334

Execute a CLI command by dispatching to all services that declared it.

Services are executed in the order they were initialized (which follows the dependency graph). The serviceFilter filters to specific services by name (supports suffix matching).

Each service's command handler is called with the parsed arguments as positional parameters. A handler returning a number sets the exit code: the highest one wins, any other result counts as 0.

Parameters​

cmdName​

string

The command name to execute (e.g., "serve", "migrate")

cmdInfo​

ServiceCommandInfo

The merged command definition from collectServiceCommands

args​

{[key: string]: any; }

Parsed argument values keyed by argument name

services​

{[key: string]: AbstractService<ServiceParameters, { }>; }

Map of service name to service instance (from Core.getServices())

serviceFilter?​

string[]

Optional list of service names to filter to (supports suffix matching)

Returns​

Promise<number>

the highest exit code returned by the handlers (0 on success), 1 if no services match the filter, a method is missing or no service instance ran

Example​

// Execute "migrate" on all services:
await executeServiceCommand("migrate", cmdInfo, { dryRun: true }, core.getServices());

// Execute "migrate" on a specific service:
await executeServiceCommand("migrate", cmdInfo, { dryRun: true }, core.getServices(), ["PostgresMigrator"]);