Skip to content

command

Launch or update the extension command.

Functions

command.updateDetail

updateDetail(options: UpdateDetailOptions): Promise<void>;

Update the details of the current command.

Example

import { _extension } from '@altdot/extension';
export default async function ActionCommand() {
// update subtitle
await _extension.command.updateDetail({ subtitle: 'Hello world' });
// clear subtitle
await _extension.command.updateDetail({ subtitle: null });
}

command.launch

command.launch<T = unknown>(options: LaunchOptions): Promise<LaunchResult<T> | null>;

Launch another command of the extension. It will return an error if the command is disabled or does not exist.

Example

import { _extension } from '@altdot/extension';
export default async function Command() {
const launchResult = await _extension.command.launch({
name: 'calculate',
args: { valA: 50, valB: 19 },
});
if (result.success) console.log(launchResult.result);
else console.error(launchResult.errorMessage);
}

Types

command.UpdateDetailOptions

Options for the command.updateDetail method.

interface UpdateDetailOptions {
subtitle?: string | null;
}
PropertyTypeDescription
subtitle?(string | null)The command’s subtitle

command.LaunchOptions

Options for the command.launch method.

interface LaunchOptions {
name: string;
waitUntilFinished?: boolean;
args?: Record<string, unknown>;
captureAllScriptMessages?: boolean;
}
PropertyTypeDescription
namestringName of the command defined in the extension manifest
waitUntilFinished?booleanWhether to wait for the command to finish running. default to true
This option not working for the command that has a view
args?Record<string, unknown>The command arguments as defined in the extension manifest
captureAllScriptMessages?booleanBy default the script type command only return the last stdout message when the waitUntilFinished is true. Set this option to true to capture all the messages.

command.LaunchResult

Result when the launched command is finished running.

type LaunchResult<T = unknown> =
| { success: true; result: T }
| { success: false; errorMessage: string };
PropertyTypeDescription
successbooleanWhether the command is successfully running
resultunknownThe output of the command when it’s successfully running
errorMessagestringError message when the command fails to run or throws an error while running