UNPKG

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