Skip to content

CLI Namespace

Types and classes exposed under the CLI namespace.

Constants

CLI.ValidEvents

ts
["command"] as const

List of valid event names supported by CLI, CLI.Command, and CLI.Command.Option.

Types

CLI.ValidEvent

ts
type CLI.ValidEvent = (typeof CLI.ValidEvents)[number]

Union of valid event names. Currently only "command".

Classes

CLI.Command

A command in a CLI.

Constructor

ts
new CLI.Command(name: string, commandcreatorfunction: Function)

Creates a new command instance. This constructor is called internally by CLI.command(...).

Properties

PropertyTypeDescription
namestringThe command name.

Methods

.on(event: CLI.ValidEvent, func: ({ commandArgs, options }) => any)
ArgumentTypeDescription
eventCLI.ValidEventThe event name. Currently only "command" is valid.
funcfunctionCallback invoked when the event fires.

Registers a handler for this command.

Event payload:

ts
{
  commandArgs: string[];
  options: { option: string; arguments: string[] }[];
}
.option(name: string)
ArgumentTypeDescription
namestringThe option name.

Creates a new option under this command. Returns a CLI.Command.Option instance.

.command(...args: any[])

Forwards to the parent CLI command(...) creator function.

CLI.Command.Option

An option that belongs to a CLI.Command.

Constructor

ts
new CLI.Command.Option(
  name: string,
  optioncreatorfunc: Function,
  commandcreatorfunction: Function
)

Creates a new option instance. This constructor is called internally by Command.option(...).

Properties

PropertyTypeDescription
namestringThe option name.

Methods

.on(event: CLI.ValidEvent, func: ({ commandArgs, options }) => any)
ArgumentTypeDescription
eventCLI.ValidEventThe event name. Currently only "command" is valid.
funcfunctionCallback invoked when the event fires.

Registers a handler for this option.

Event payload:

ts
{
  commandArgs: string[];
  options: { option: string; arguments: string[] }[];
}
.command(...args: any[])

Forwards to the parent CLI command(...) creator function.

.option(...args: any[])

Forwards to the parent command option(...) creator function.