UNPKG

7.53 kBTypeScriptView Raw
1/**
2 * A table option configuration type that can be the TableOptions as defined by
3 * [oclif/cli-ux](https://github.com/oclif/cli-ux/blob/master/src/styled/table.ts) or a string array of table keys to be used as table headers
4 * for simple tables.
5 * @typedef {object} SfdxTableOptions
6 * @property {TableOptions | string[]} options
7 */
8/**
9 * A prompt option configuration as defined by
10 * [oclif/cli-ux](https://github.com/oclif/cli-ux/blob/master/src/prompt.ts).
11 * @typedef {object} IPromptOptions
12 * @property {string} prompt The prompt string displayed to the user.
13 * @property {'normal' | 'mask' | 'hide'} type `Normal` does not hide the user input, `mask` hides the user input after the user presses `ENTER`, and `hide` hides the user input as it is being typed.
14 */
15import { Logger } from '@salesforce/core';
16import { Optional } from '@salesforce/ts-types';
17import { cli, IPromptOptions } from 'cli-ux';
18import { TableOptions as OclifTableOptions } from 'cli-ux/lib/styled/table';
19/**
20 * Utilities for interacting with terminal I/O.
21 */
22export declare class UX {
23 private logger;
24 /**
25 * Collection of warnings that can be accessed and manipulated later.
26 * @type {Set<string>}
27 */
28 static warnings: Set<string>;
29 /**
30 * Formats a deprecation warning for display to `stderr`, `stdout`, and/or logs.
31 *
32 * @param {DeprecationDefinition} def The definition for the deprecated object.
33 * @returns {string} The formatted deprecation message.
34 */
35 static formatDeprecationWarning(def: DeprecationDefinition): string;
36 /**
37 * Create a `UX` instance.
38 *
39 * @returns {Promise<UX>} A `Promise` of the created `UX` instance.
40 */
41 static create(): Promise<UX>;
42 cli: typeof cli;
43 private isOutputEnabled;
44 /**
45 * Do not directly construct instances of this class -- use {@link UX.create} instead.
46 */
47 constructor(logger: Logger, isOutputEnabled?: boolean, ux?: typeof cli);
48 /**
49 * Logs at `INFO` level and conditionally writes to `stdout` if stream output is enabled.
50 *
51 * @param {...any[]} args The messages or objects to log.
52 * @returns {UX}
53 */
54 log(...args: string[]): UX;
55 /**
56 * Log JSON to stdout and to the log file with log level info.
57 *
58 * @param {object} obj The object to log -- must be serializable as JSON.
59 * @returns {UX}
60 * @throws {TypeError} If the object is not JSON-serializable.
61 */
62 logJson(obj: object): UX;
63 /**
64 * Prompt the user for input.
65 * @param {string} name The string that the user sees when prompted for information.
66 * @param {IPromptOptions} options A prompt option configuration.
67 * @returns {Promise<string>} The user input to the prompt.
68 */
69 prompt(name: string, options?: IPromptOptions): Promise<string>;
70 /**
71 * Prompt the user for confirmation.
72 * @param {string} message The message displayed to the user.
73 * @returns {Promise<boolean>} Returns `true` if the user inputs 'y' or 'yes', and `false` if the user inputs 'n' or 'no'.
74 */
75 confirm(message: string): Promise<boolean>;
76 /**
77 * Start a spinner action after displaying the given message.
78 * @param {string} message The message displayed to the user.
79 */
80 startSpinner(message: string): void;
81 /**
82 * Pause the spinner and call the given function.
83 * @param {function} fn The function to be called in the pause.
84 * @param {string} icon The string displayed to the user.
85 * @returns {T} The result returned by the passed in function.
86 */
87 pauseSpinner<T>(fn: () => T, icon?: string): Optional<T>;
88 /**
89 * Update the spinner status.
90 * @param {string} status The message displayed to the user.
91 */
92 setSpinnerStatus(status?: string): void;
93 /**
94 * Get the spinner status.
95 * @returns {Optional<string>}
96 */
97 getSpinnerStatus(): Optional<string>;
98 /**
99 * Stop the spinner action.
100 * @param {string} message The message displayed to the user.
101 */
102 stopSpinner(message?: string): void;
103 /**
104 * Logs a warning as `WARN` level and conditionally writes to `stderr` if the log
105 * level is `WARN` or above and stream output is enabled. The message is added
106 * to the static {@link UX.warnings} set if stream output is _not_ enabled, for later
107 * consumption and manipulation.
108 *
109 * @param {string} message The warning message to output.
110 * @returns {UX}
111 * @see UX.warnings
112 */
113 warn(message: string): UX;
114 /**
115 * Logs an error at `ERROR` level and conditionally writes to `stderr` if stream
116 * output is enabled.
117 *
118 * @param {...any[]} args The errors to log.
119 * @returns {UX}
120 */
121 error(...args: unknown[]): UX;
122 /**
123 * Logs an object as JSON at `ERROR` level and to `stderr`.
124 *
125 * @param {object} obj The error object to log -- must be serializable as JSON.
126 * @returns {UX}
127 * @throws {TypeError} If the object is not JSON-serializable.
128 */
129 errorJson(obj: object): UX;
130 /**
131 * Logs at `INFO` level and conditionally writes to `stdout` in a table format if
132 * stream output is enabled.
133 *
134 * @param {object[]} rows The rows of data to be output in table format.
135 * @param {SfdxTableOptions} options The {@link SfdxTableOptions} to use for formatting.
136 * @returns {UX}
137 */
138 table(rows: any[], options?: TableOptions): UX;
139 /**
140 * Logs at `INFO` level and conditionally writes to `stdout` in a styled object format if
141 * stream output is enabled.
142 *
143 * @param {object} obj The object to be styled for stdout.
144 * @param {string[]} [keys] The object keys to be written to stdout.
145 * @returns {UX}
146 */
147 styledObject(obj: object, keys?: string[]): UX;
148 /**
149 * Log at `INFO` level and conditionally write to `stdout` in styled JSON format if
150 * stream output is enabled.
151 *
152 * @param {object} obj The object to be styled for stdout.
153 * @returns {UX}
154 */
155 styledJSON(obj: object): UX;
156 /**
157 * Logs at `INFO` level and conditionally writes to `stdout` in a styled header format if
158 * stream output is enabled.
159 *
160 * @param {string} header The header to be styled.
161 * @returns {UX}
162 */
163 styledHeader(header: string): UX;
164}
165/**
166 * A table option configuration type. May be a detailed configuration, or
167 * more simply just a string array in the simple cases where table header values
168 * are the only desired config option.
169 */
170export declare type TableOptions = Partial<OclifTableOptions> | string[];
171/**
172 * A deprecation configuration type. A typical instance can pass `name`,
173 * `type`, and `version` for a standard message. Alternatively, the `messageOverride` can
174 * be used as a special case deprecated message. Used when defining a deprecation on a
175 * command or flag.
176 */
177export declare type Deprecation = {
178 to?: string;
179 message?: string;
180} & ({
181 version: number | string;
182} | {
183 messageOverride: string;
184});
185/**
186 * A deprecation warning message configuration type. A typical instance can pass `name`,
187 * `type`, and `version` for a standard message. Alternatively, the `messageOverride` can
188 * be used as a special case deprecated message. Used when formating a deprecation message.
189 */
190export declare type DeprecationDefinition = {
191 to?: string;
192 message?: string;
193} & ({
194 version: number | string;
195 name: string;
196 type: string;
197} | {
198 messageOverride: string;
199});
200
\No newline at end of file