Skip to content

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 ParameterDefault typeDescription
G extends GunshiParamsConstraintDefaultGunshiParamsA GunshiParamsConstraint type
A extends ArgsExtractArgs<G>An Args type extracted from GunshiParamsConstraint
C extends InferCommandProps<G>InferCommandProps<G>A Command type inferred from GunshiParamsConstraint

Parameters

ParameterTypeDescription
definitionC & 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');
    }
  }
})

Released under the MIT License.