Skip to content

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

NameDescription
A extends ArgsAn Args type

Parameters

NameTypeDescription
loaderCommandLoader<{ 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<
  D extends { args: Args } & Partial<Command<{ args: D['args']; extensions: {} }>>
>(loader: CommandLoader<{ args: D['args']; extensions: {} }>, definition: D): LazyCommand<{ args: D['args']; extensions: {} }, D>

Define a lazy command with definition.

Type Parameters

NameDescription
D extends { args: Args } & Partial<Command<{ args: D['args']; extensions: {} }>>A partial Command definition type with required args

Parameters

NameTypeDescription
loaderCommandLoader<{ args: D['args']; extensions: {} }>A command loader function that returns a command definition
definitionDA command definition

Returns

LazyCommand<{ args: D['args']; 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)

Call Signature

ts
export function lazy<
  G extends GunshiParamsConstraint = DefaultGunshiParams,
  D extends Partial<Command<G>> = Partial<Command<G>>
>(loader: CommandLoader<G>, definition?: D): LazyCommand<G, D>

Define a lazy command with explicit Gunshi parameters and optional definition.

Type Parameters

NameDescription
G extends GunshiParamsConstraint = DefaultGunshiParamsA GunshiParamsConstraint
D extends Partial<Command<G>> = Partial<Command<G>>A partial Command definition type

Parameters

NameTypeDescription
loaderCommandLoader<G>A command loader function that returns a command definition
definitionDAn optional command definition (optional)

Returns

LazyCommand<G, D> — A lazy command that can be executed later

Released under the MIT License.