UNPKG

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