Skip to content

Function: define()

Define a command.

Signature

ts
export function define<
  G extends GunshiParamsConstraint = DefaultGunshiParams,
  A extends Args = ExtractArgs<G>,
  C extends Partial<Command<{ args: A; extensions: ExtractExtensions<G> }>> = {}
>(definition: CommandDefinition<A, ExtractExtensions<G>, C>): CommandDefinitionResult<G, C>

Type Parameters

NameDescription
G extends GunshiParamsConstraint = DefaultGunshiParamsA GunshiParamsConstraint type
A extends Args = ExtractArgs<G>An Args type extracted from GunshiParamsConstraint
C extends Partial<Command<{ args: A; extensions: ExtractExtensions<G> }>> = {}A Command type inferred from GunshiParamsConstraint

Parameters

NameTypeDescription
definitionCommandDefinition<A, ExtractExtensions<G>, C>A command definition

Returns

CommandDefinitionResult<G, C> — A defined command

Examples

ts
const command = define({
  name: 'test',
  description: 'A test command',
  args: {
    debug: {
      type: 'boolean',
      description: 'Enable debug mode',
      default: false
    }
  },
  run: ctx => {
    if (ctx.values.debug) {
      console.debug('Debug mode is enabled');
    }
  }
})

Released under the MIT License.