From b2a28dba0b8b954621fc2a7cbdc5287d586fa4b1 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Mon, 11 Mar 2024 11:54:45 +0100 Subject: [PATCH] docs: document command namespace in api (#6353) * docs: document command namespace in api Signed-off-by: Philippe Martin * Update packages/extension-api/src/extension-api.d.ts Co-authored-by: Florent BENOIT Signed-off-by: Philippe Martin --------- Signed-off-by: Philippe Martin Co-authored-by: Florent BENOIT --- packages/extension-api/src/extension-api.d.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/extension-api/src/extension-api.d.ts b/packages/extension-api/src/extension-api.d.ts index 55ae357e8ed..e5a0db868dd 100644 --- a/packages/extension-api/src/extension-api.d.ts +++ b/packages/extension-api/src/extension-api.d.ts @@ -465,8 +465,27 @@ declare module '@podman-desktop/api' { } export namespace commands { + /** + * Define a command, to be executed later, either by calling {@link commands.executeCommand} or by referencing its name in the `command` field of a {@link StatusBarItem}. + * + * @param command the name of the command. The name must be unique over all extensions. It is recommended to prefix this name with the name of the extension, to avoid conflicts with commands from other extensions. + * @param callback the command to execute + * @param thisArg The value of `this` provided for the call to callback + * @returns A disposable that unregisters this command when being disposed + * @throws if a command with the same name is already registered. + */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable; + /** + * Execute a command, previously registered with {@link commands.registerCommand} + * + * @param command the name used for registering the command + * @param rest the parameters to pass to the command + * @param T the type of the value returned by the command + * @returns the value returned by the command + * @throws if the command is not registered + * @throws if the command throws an exception + */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function executeCommand(command: string, ...rest: any[]): PromiseLike; } @@ -1194,7 +1213,7 @@ declare module '@podman-desktop/api' { */ enabled: boolean; /** - * The identifier of a command to run on click. + * The identifier of a command, previously registered with {@link commands.registerCommand}, to run on click. */ command?: string; /**