gunshi / default / PluginContext
Interface: PluginContext<G>
Gunshi plugin context interface.
Since
v0.27.0
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
G extends GunshiParamsConstraint | DefaultGunshiParams | A type extending GunshiParams to specify the shape of command parameters. |
Methods
addCommand()
ts
addCommand(name, command): void;Add a sub command.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Command name |
command | | Command<G> | LazyCommand<G> | Command definition |
Returns
void
addGlobalOption()
ts
addGlobalOption(name, schema): void;Add a global option.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | An option name |
schema | ArgSchema | An ArgSchema for the option |
Returns
void
decorateCommand()
ts
decorateCommand<L>(decorator): void;Decorate the command execution.
Decorators are applied in reverse order (last registered is executed first).
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
L extends Record<string, unknown> | object | An extensions type to specify the shape of CommandContext's extensions. |
Parameters
| Parameter | Type | Description |
|---|---|---|
decorator | (baseRunner) => (ctx) => Awaitable<string | void> | A decorator function that wraps the command runner |
Returns
void
decorateHeaderRenderer()
ts
decorateHeaderRenderer<L>(decorator): void;Decorate the header renderer.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
L extends Record<string, unknown> | object | An extensions type to specify the shape of CommandContext's extensions. |
Parameters
| Parameter | Type | Description |
|---|---|---|
decorator | (baseRenderer, ctx) => Promise<string> | A decorator function that wraps the base header renderer. |
Returns
void
decorateUsageRenderer()
ts
decorateUsageRenderer<L>(decorator): void;Decorate the usage renderer.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
L extends Record<string, unknown> | object | An extensions type to specify the shape of CommandContext's extensions. |
Parameters
| Parameter | Type | Description |
|---|---|---|
decorator | (baseRenderer, ctx) => Promise<string> | A decorator function that wraps the base usage renderer. |
Returns
void
decorateValidationErrorsRenderer()
ts
decorateValidationErrorsRenderer<L>(decorator): void;Decorate the validation errors renderer.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
L extends Record<string, unknown> | object | An extensions type to specify the shape of CommandContext's extensions. |
Parameters
| Parameter | Type | Description |
|---|---|---|
decorator | (baseRenderer, ctx, error) => Promise<string> | A decorator function that wraps the base validation errors renderer. |
Returns
void
hasCommand()
ts
hasCommand(name): boolean;Check if a command exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Command name |
Returns
boolean
True if the command exists, false otherwise
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
globalOptions | readonly | Map<string, ArgSchema> | Get the global options |
subCommands | readonly | ReadonlyMap<string, | Command<G> | LazyCommand<G>> | Get the registered sub commands |
