Skip to main content

Command

@webda/core


Variable: Command

const Command: {(value, context): any; (...args): (value, context) => any; }

Defined in: packages/core/src/services/command.ts:92

Declare a CLI command on a service method.

The method parameters define the CLI arguments automatically:

  • Parameter name becomes the --flag name (e.g., port → --port)
  • TypeScript type annotation determines the flag type (string, number, boolean)
  • Default value from the method signature becomes the flag default
  • JSDoc @alias on parameter provides a single-character shorthand (e.g., -p)
  • JSDoc @description on parameter provides help text for the flag
  • JSDoc @deprecated on parameter marks the flag as deprecated

Multiple services can declare the same command name — they all run in dependency-graph order. Use --service=ServiceName to filter at invocation.

Subcommands use space-separated names. The service owns its subtree: @Command("aws s3") handles everything under webda aws s3.

Call Signature​

(value, context): any

Parameters​

value​

any

context​

ClassMethodDecoratorContext

Returns​

any

Call Signature​

(...args): (value, context) => any

Parameters​

args​

...[string, CommandOptions]

Returns​

(value, context) => any

Param​

name

Command name, space-separated for subcommands (e.g., "serve", "aws s3")

Param​

options

Command options including description

Examples​

Simple command

class HttpServer extends Service {
@Command("serve", { description: "Start the HTTP server" })
async serve(
/** @alias b @description Bind address */
bind: string = "127.0.0.1",
/** @alias p @description Port to listen on */
port: number = 18080
): Promise<void> { ... }
}
// Usage: webda serve --port 3000 --bind 0.0.0.0
// Usage: webda serve -p 3000 -b 0.0.0.0

Subcommand

class S3Service extends Service {
@Command("aws s3", { description: "Manage S3 buckets" })
async s3(bucket?: string): Promise<void> { ... }
}
// Usage: webda aws s3 --bucket my-bucket

Composable command (multiple services)

class PostgresMigrator extends Service {
@Command("migrate", { description: "Run PostgreSQL migrations" })
async migrate(dryRun: boolean = false): Promise<void> { ... }
}
class MongoMigrator extends Service {
@Command("migrate", { description: "Run MongoDB migrations" })
async migrate(dryRun: boolean = false): Promise<void> { ... }
}
// webda migrate → runs both
// webda migrate --service=PostgresMigrator → runs only PostgreSQL