Skip to content

gunshi / default / PluginContext

Interface: PluginContext<G>

Gunshi plugin context interface.

Since

v0.27.0

Type Parameters

Type ParameterDefault type
G extends GunshiParamsConstraintDefaultGunshiParams

Methods

addCommand()

ts
addCommand(name, command): void;

Add a sub command.

Parameters

ParameterTypeDescription
namestringCommand name
command| Command<G> | LazyCommand<G>Command definition

Returns

void


addGlobalOption()

ts
addGlobalOption(name, schema): void;

Add a global option.

Parameters

ParameterTypeDescription
namestringAn option name
schemaArgSchemaAn 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 ParameterDefault type
L extends Record<string, unknown>object

Parameters

ParameterTypeDescription
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 ParameterDefault type
L extends Record<string, unknown>object

Parameters

ParameterTypeDescription
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 ParameterDefault type
L extends Record<string, unknown>object

Parameters

ParameterTypeDescription
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 ParameterDefault type
L extends Record<string, unknown>object

Parameters

ParameterTypeDescription
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

ParameterTypeDescription
namestringCommand name

Returns

boolean

True if the command exists, false otherwise

Properties

PropertyModifierTypeDescription
globalOptionsreadonlyMap<string, ArgSchema>Get the global options
subCommandsreadonlyReadonlyMap<string, | Command<G> | LazyCommand<G>>Get the registered sub commands

Released under the MIT License.