gunshi / definition / lazy
Function: lazy()
Define a lazy command with or without definition.
Param
A command loader function that returns a command definition
Param
An optional command definition
Call Signature
ts
function lazy<A>(loader): LazyCommand<{
args: A;
extensions: {
};
}, {
}>;Define a lazy command.
Type Parameters
| Type Parameter | Description |
|---|---|
A extends Args | An Args type |
Parameters
| Parameter | Type | Description |
|---|---|---|
loader | CommandLoader<{ args: A; extensions: { }; }> | A command loader |
Returns
LazyCommand<{ args: A; extensions: { }; }, { }>
A lazy command with loader
Example
ts
// load command with dynamic importing
const test = lazy(() => import('./commands/test'))Call Signature
ts
function lazy<G, A, D>(loader, definition): LazyCommand<{
args: A;
extensions: {
};
}, D>;Define a lazy command with definition.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
G extends GunshiParamsConstraint | DefaultGunshiParams | - |
A extends Args | ExtractArgs<G> | An Args type |
D extends Partial<Command<{ args: A; extensions: { }; }>> | Partial<Command<{ args: A; extensions: { }; }>> | A partial Command definition type |
Parameters
| Parameter | Type | Description |
|---|---|---|
loader | CommandLoader<{ args: A; extensions: { }; }> | A command loader function that returns a command definition |
definition | D | An optional command definition |
Returns
LazyCommand<{ args: A; extensions: { }; }, D>
A lazy command that can be executed later
Example
ts
// define command without command runner
const testDefinition = define({
name: 'test',
description: 'Test command',
args: {
debug: {
type: 'boolean',
description: 'Enable debug mode',
default: false
}
},
})
// define load command with command runner and defined command
const test = lazy((): CommandRunner<{ args: typeof testDefinition.args; extensions: {} }> => {
return ctx => {
if (ctx.values.debug) {
console.debug('Debug mode is enabled');
}
}
}, testDefinition)