gunshi / definition / define
Function: define()
ts
function define<G, A, C>(definition): { [K in string | number | symbol]: (Pick<C, keyof C> & Partial<Pick<Command<G>, Exclude<"name", keyof C> | Exclude<"description", keyof C> | Exclude<"run", keyof C> | Exclude<"args", keyof C> | Exclude<"examples", keyof C> | Exclude<"toKebab", keyof C> | Exclude<"internal", keyof C> | Exclude<"entry", keyof C> | Exclude<"rendering", keyof C>>>)[K] };Define a command.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
G extends GunshiParamsConstraint | DefaultGunshiParams | A GunshiParamsConstraint type |
A extends Args | ExtractArgs<G> | An Args type extracted from GunshiParamsConstraint |
C extends InferCommandProps<G> | InferCommandProps<G> | A Command type inferred from GunshiParamsConstraint |
Parameters
| Parameter | Type | Description |
|---|---|---|
definition | C & Command<{ args: A; extensions: ExtractExtensions<G>; }> | A command definition |
Returns
{ [K in string | number | symbol]: (Pick<C, keyof C> & Partial<Pick<Command<G>, Exclude<"name", keyof C> | Exclude<"description", keyof C> | Exclude<"run", keyof C> | Exclude<"args", keyof C> | Exclude<"examples", keyof C> | Exclude<"toKebab", keyof C> | Exclude<"internal", keyof C> | Exclude<"entry", keyof C> | Exclude<"rendering", keyof C>>>)[K] }
A defined command
Example
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');
}
}
})