UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

73 lines (72 loc) 2.85 kB
/** * @packageDocumentation * * Contains utility classes and functions for managing task results, including * success, exit codes, and chaining multiple tasks. */ import type { Promisable } from 'type-fest'; import type { MaybeReturn } from '../Type.mjs'; /** * Abstract class representing the result of a task. Includes methods for handling success, * exit codes, and chaining tasks. */ export declare abstract class CliTaskResult { /** * Chains multiple tasks together, executing them sequentially until one fails. * * @param tasks - An array of task functions that return a {@link CliTaskResult} or `void`. * @returns A {@link Promise} that resolves with the first failed {@link CliTaskResult} or a success result. */ static chain(tasks: (() => Promisable<MaybeReturn<CliTaskResult>>)[]): Promise<CliTaskResult>; /** * Creates a {@link CliTaskResult} that does not exit the process. * * @returns A {@link CliTaskResult} that does not exit the process. */ static DoNotExit(): CliTaskResult; /** * A failure result of a CLI task. * * @returns The failure result. */ static Failure(): CliTaskResult; /** * Creates a {@link CliTaskResult} based on an exit code. * * @param exitCode - The exit code to represent. * @returns A {@link CliTaskResult} representing the exit code. */ static FromExitCode(exitCode: number): CliTaskResult; /** * Creates a CliTaskResult representing a successful task result. * * @param isSuccess - A boolean indicating whether the task was successful. Default is true. * @returns A CliTaskResult object representing a successful task result. */ static Success(isSuccess?: boolean): CliTaskResult; /** * Exits the process based on the task result. */ abstract exit(): void; /** * Determines if the task was successful. * * @returns `true` if the task was successful, otherwise `false`. */ protected abstract isSuccessful(): boolean; } /** * Converts an array of command-line arguments into a single command-line string. * Handles escaping of special characters such as spaces, quotes, and newlines. * * @param args - The array of command-line arguments to convert. * @returns A string representing the command-line invocation. */ export declare function toCommandLine(args: string[]): string; /** * Wraps a CLI task function to ensure it runs safely and handles its {@link CliTaskResult}. * * @param taskFn - The task function to execute, which may return a {@link CliTaskResult} or `void`. * @returns A {@link Promise} that resolves when the task is completed and exits with the appropriate status. */ export declare function wrapCliTask(taskFn: () => Promisable<MaybeReturn<CliTaskResult>>): Promise<void>;