API / @aionbuilders/nabu/extend

CommandDef

Type Stability: stable

A command: a label, optional default keys, a when condition, a scope and a run function. Declared by extensions (ExtensionInit.commands); every command is also an action of the bus (nabu.exec(id, data)).

Related guide: Commands and keymap →

Definition

TypeScript
import type { CommandDef } from '@aionbuilders/nabu/extend';
TypeScript
interface CommandDef {
  confirm?: CommandConfirm;
  keys?: string[];
  label: string | ((ctx: CommandContext) => string);
  run: (nabu: Nabu, ctx: CommandContext, data?: any) => any;
  scope?: string;
  when?: (ctx: CommandContext) => boolean;
}

Properties

Properties of CommandDef
PropertyTypeDescription
confirmoptionalCommandConfirmn/a
keysoptionalstring[]

default chords ('Mod-Shift-Enter', see keys.js); overridable by the keymap option

labelstring | ((ctx: CommandContext) => string)

text for help, prompts, pickers

run(nabu: Nabu, ctx: CommandContext, data?: any) => any

a SYNCHRONOUS false from a key press means "not handled": resolution goes on (next command, legacy hooks, native behavior). Any other value (a promise included) = handled.

scopeoptionalstring

block type the command belongs to: beats generic commands when the caret is in such a block, and limits the static conflict check to commands of the same scope

whenoptional(ctx: CommandContext) => boolean

where the command applies; required for a key without modifier

Source: src/lib/utils/commands.js:45