UNPKG

2.49 kBTypeScriptView Raw
1import { Errors, Interfaces } from '@oclif/core';
2type CaptureOptions = {
3 print?: boolean;
4 stripAnsi?: boolean;
5};
6type CaptureResult<T> = {
7 error?: Error & Partial<Errors.CLIError>;
8 result?: T;
9 stderr: string;
10 stdout: string;
11};
12/**
13 * Capture the stderr and stdout output of a function
14 * @param fn async function to run
15 * @param opts options
16 * - print: Whether to print the output to the console
17 * - stripAnsi: Whether to strip ANSI codes from the output
18 * @returns {Promise<CaptureResult<T>>} Captured output
19 * - error: Error object if the function throws an error
20 * - result: Result of the function if it returns a value and succeeds
21 * - stderr: Captured stderr output
22 * - stdout: Captured stdout output
23 */
24export declare function captureOutput<T>(fn: () => Promise<unknown>, opts?: CaptureOptions): Promise<CaptureResult<T>>;
25/**
26 * Capture the stderr and stdout output of a command in your CLI
27 * @param args Command arguments, e.g. `['my:command', '--flag']` or `'my:command --flag'`
28 * @param loadOpts options for loading oclif `Config`
29 * @param captureOpts options for capturing the output
30 * - print: Whether to print the output to the console
31 * - stripAnsi: Whether to strip ANSI codes from the output
32 * @returns {Promise<CaptureResult<T>>} Captured output
33 * - error: Error object if the command throws an error
34 * - result: Result of the command if it returns a value and succeeds
35 * - stderr: Captured stderr output
36 * - stdout: Captured stdout output
37 */
38export declare function runCommand<T>(args: string | string[], loadOpts?: Interfaces.LoadOptions, captureOpts?: CaptureOptions): Promise<CaptureResult<T>>;
39/**
40 * Capture the stderr and stdout output of a hook in your CLI
41 * @param hook Hook name
42 * @param options options to pass to the hook
43 * @param loadOpts options for loading oclif `Config`
44 * @param captureOpts options for capturing the output
45 * - print: Whether to print the output to the console
46 * - stripAnsi: Whether to strip ANSI codes from the output
47 * @returns {Promise<CaptureResult<T>>} Captured output
48 * - error: Error object if the hook throws an error
49 * - result: Result of the hook if it returns a value and succeeds
50 * - stderr: Captured stderr output
51 * - stdout: Captured stdout output
52 */
53export declare function runHook<T>(hook: string, options: Record<string, unknown>, loadOpts?: Interfaces.LoadOptions, captureOpts?: CaptureOptions): Promise<CaptureResult<T>>;
54export {};