Function: lazy()
Define a lazy command with or without definition.
Call Signature
ts
export function lazy<A extends Args>(loader: CommandLoader<{ args: A; extensions: {} }>): LazyCommand<{ args: A; extensions: {} }, {}>Define a lazy command.
Type Parameters
| Name | Description |
|---|---|
A extends Args | An Args type |
Parameters
| Name | Type | Description |
|---|---|---|
loader | CommandLoader<{ args: A; extensions: {} }> | A command loader |
Returns
LazyCommand<{ args: A; extensions: {} }, {}> — A lazy command with loader
Examples
ts
// load command with dynamic importing
const test = lazy(() => import('./commands/test'))Call Signature
ts
export function lazy<
G extends GunshiParamsConstraint = DefaultGunshiParams,
A extends ExtractArgs<G> = ExtractArgs<G>,
D extends Partial<Command<{ args: A; extensions: {} }>> = Partial<
Command<{ args: A; extensions: {} }>
>
>(loader: CommandLoader<{ args: A; extensions: {} }>, definition: D): LazyCommand<{ args: A; extensions: {} }, D>Define a lazy command with definition.
Type Parameters
| Name | Description |
|---|---|
G extends GunshiParamsConstraint = DefaultGunshiParams | - |
A extends ExtractArgs<G> = ExtractArgs<G> | An Args type |
D extends Partial<Command<{ args: A; extensions: {} }>> = Partial<Command<{ args: A; extensions: {} }>> | A partial Command definition type |
Parameters
| Name | 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
Examples
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)