@salesforce/sf-plugins-core 1.14.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,49 +15,148 @@ export declare const StandardColors: {
15
15
  success: chalk.Chalk;
16
16
  };
17
17
  /**
18
- * A base command that provides convenient access to CLI help
19
- * output formatting. Extend this command and set specific properties
20
- * to add help sections to the command's help output.
18
+ * A base command that provided common functionality for all sf commands.
19
+ * Functionality includes:
20
+ * - JSON support
21
+ * - progress bars
22
+ * - spinners
23
+ * - prompts
24
+ * - stylized output (JSON, url, objects, headers)
25
+ * - lifecycle events
26
+ * - configuration variables help section
27
+ * - environment variables help section
28
+ * - error codes help section
21
29
  *
22
- * @extends @oclif/core/command
23
- * @see https://github.com/oclif/core/blob/main/src/command.ts
30
+ * All implementations of this class need to implement the run() method.
31
+ *
32
+ * Additionally, all implementations of this class need to provide a generic type that describes the JSON output.
33
+ *
34
+ * See {@link https://github.com/salesforcecli/plugin-template-sf/blob/main/src/commands/hello/world.ts example implementation}.
35
+ *
36
+ * @example
37
+ *
38
+ * ```
39
+ * import { SfCommand } from '@salesforce/sf-plugins-core';
40
+ * export type MyJsonOutput = { success: boolean };
41
+ * export default class MyCommand extends SfCommand<MyJsonOutput> {
42
+ * public async run(): Promise<MyJsonOutput> {
43
+ * return { success: true };
44
+ * }
45
+ * }
46
+ * ```
24
47
  */
25
48
  export declare abstract class SfCommand<T> extends Command {
26
49
  static SF_ENV: string;
27
50
  static enableJsonFlag: boolean;
51
+ /**
52
+ * Add a CONFIGURATION VARIABLES section to the help output.
53
+ *
54
+ * @example
55
+ * ```
56
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
57
+ * import { OrgConfigProperties } from '@salesforce/core';
58
+ * export default class MyCommand extends SfCommand {
59
+ * public static configurationVariablesSection = toHelpSection(
60
+ * 'CONFIGURATION VARIABLES',
61
+ * OrgConfigProperties.TARGET_ORG,
62
+ * OrgConfigProperties.ORG_API_VERSION,
63
+ * );
64
+ * }
65
+ * ```
66
+ */
28
67
  static configurationVariablesSection?: HelpSection;
68
+ /**
69
+ * Add an Environment VARIABLES section to the help output.
70
+ *
71
+ * @example
72
+ * ```
73
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
74
+ * import { EnvironmentVariable } from '@salesforce/core';
75
+ * export default class MyCommand extends SfCommand {
76
+ * public static envVariablesSection = toHelpSection(
77
+ * 'ENVIRONMENT VARIABLES',
78
+ * EnvironmentVariable.SF_TARGET_ORG,
79
+ * EnvironmentVariable.SF_USE_PROGRESS_BAR,
80
+ * );
81
+ * }
82
+ * ```
83
+ */
29
84
  static envVariablesSection?: HelpSection;
85
+ /**
86
+ * Add an ERROR CODES section to the help output.
87
+ *
88
+ * @example
89
+ * ```
90
+ * import { SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
91
+ * export default class MyCommand extends SfCommand {
92
+ * public static errorCodes = toHelpSection(
93
+ * 'ERROR CODES',
94
+ * { 0: 'Success', 1: 'Failure' },
95
+ * );
96
+ * }
97
+ * ```
98
+ */
30
99
  static errorCodes?: HelpSection;
100
+ /**
101
+ * Flags that you can use for manipulating tables.
102
+ *
103
+ * @example
104
+ * ```
105
+ * import { SfCommand } from '@salesforce/sf-plugins-core';
106
+ * export default class MyCommand extends SfCommand {
107
+ * public static flags = {
108
+ * ...SfCommand.tableFags,
109
+ * 'my-flags: flags.string({ char: 'm', description: 'my flag' }),
110
+ * }
111
+ * }
112
+ * ```
113
+ */
31
114
  static tableFlags: typeof CliUx.Table.table.flags;
115
+ /**
116
+ * Set to true if the command must be executed inside a Salesforce project directory.
117
+ *
118
+ * If set to true the command will throw an error if the command is executed outside of a Salesforce project directory.
119
+ * Additionally, this.project will be set to the current Salesforce project (SfProject).
120
+ *
121
+ */
32
122
  static requiresProject: boolean;
123
+ /**
124
+ * Add a spinner to the console. {@link Spinner}
125
+ */
33
126
  spinner: Spinner;
127
+ /**
128
+ * Add a progress bar to the console. {@link Progress}
129
+ */
34
130
  progress: Progress;
35
131
  project: SfProject;
36
132
  private warnings;
37
133
  private ux;
38
134
  private prompter;
39
135
  private lifecycle;
40
- protected get statics(): typeof SfCommand;
41
136
  constructor(argv: string[], config: Config);
137
+ protected get statics(): typeof SfCommand;
42
138
  /**
43
- * Log a success message that has the standard success message color applied
139
+ * Log a success message that has the standard success message color applied.
44
140
  *
45
- * @param message
46
- * @param args
141
+ * @param message The message to log.
47
142
  */
48
143
  logSuccess(message: string): void;
49
144
  /**
50
- * Log warning to users. If --json is enabled, then the warning
51
- * will be added to the json output under the warnings property.
145
+ * Log warning to users. If --json is enabled, then the warning will be added to the json output under the warnings property.
146
+ *
147
+ * @param input {@link SfCommand.Warning} The message to log.
52
148
  */
53
149
  warn(input: SfCommand.Warning): SfCommand.Warning;
54
150
  /**
55
151
  * Log info message to users.
152
+ *
153
+ * @param input {@link SfCommand.Info} The message to log.
56
154
  */
57
155
  info(input: SfCommand.Info): void;
58
156
  /**
59
- * Warn user about sensitive information (access tokens, etc...) before
60
- * logging to the console.
157
+ * Warn user about sensitive information (access tokens, etc...) before logging to the console.
158
+ *
159
+ * @param msg The message to log.
61
160
  */
62
161
  logSensitive(msg?: string): void;
63
162
  /**
@@ -66,18 +165,27 @@ export declare abstract class SfCommand<T> extends Command {
66
165
  table<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>, options?: Ux.Table.Options): void;
67
166
  /**
68
167
  * Log a stylized url to the console. Will automatically be suppressed when --json flag is present.
168
+ *
169
+ * @param text The text to display for the url.
170
+ * @param uri The url to display.
69
171
  */
70
172
  url(text: string, uri: string, params?: {}): void;
71
173
  /**
72
174
  * Log stylized JSON to the console. Will automatically be suppressed when --json flag is present.
175
+ *
176
+ * @param obj The JSON to log.
73
177
  */
74
178
  styledJSON(obj: AnyJson): void;
75
179
  /**
76
180
  * Log stylized object to the console. Will automatically be suppressed when --json flag is present.
181
+ *
182
+ * @param obj The object to log.
77
183
  */
78
184
  styledObject(obj: AnyJson): void;
79
185
  /**
80
186
  * Log stylized header to the console. Will automatically be suppressed when --json flag is present.
187
+ *
188
+ * @param text the text to display as a header.
81
189
  */
82
190
  styledHeader(text: string): void;
83
191
  /**
@@ -93,9 +201,9 @@ export declare abstract class SfCommand<T> extends Command {
93
201
  * await this.prompt();
94
202
  * }
95
203
  */
96
- prompt<R = Prompter.Answers>(questions: Prompter.Questions<R>, initialAnswers?: Partial<R>): Promise<R>;
204
+ prompt<R extends Prompter.Answers>(questions: Prompter.Questions<R>, initialAnswers?: Partial<R>): Promise<R>;
97
205
  /**
98
- * Simplified prompt for single-question confirmation. Times out and throws after 10s
206
+ * Simplified prompt for single-question confirmation. Times out and throws after 10s
99
207
  *
100
208
  * @param message text to display. Do not include a question mark.
101
209
  * @param ms milliseconds to wait for user input. Defaults to 10s.
@@ -105,7 +213,7 @@ export declare abstract class SfCommand<T> extends Command {
105
213
  /**
106
214
  * Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
107
215
  */
108
- timedPrompt<R = Prompter.Answers>(questions: Prompter.Questions<R>, ms?: number, initialAnswers?: Partial<R>): Promise<R>;
216
+ timedPrompt<R extends Prompter.Answers>(questions: Prompter.Questions<R>, ms?: number, initialAnswers?: Partial<R>): Promise<R>;
109
217
  _run<R>(): Promise<R | undefined>;
110
218
  /**
111
219
  * Wrap the command result into the standardized JSON structure.
package/lib/sfCommand.js CHANGED
@@ -21,12 +21,35 @@ exports.StandardColors = {
21
21
  success: chalk.bold.green,
22
22
  };
23
23
  /**
24
- * A base command that provides convenient access to CLI help
25
- * output formatting. Extend this command and set specific properties
26
- * to add help sections to the command's help output.
24
+ * A base command that provided common functionality for all sf commands.
25
+ * Functionality includes:
26
+ * - JSON support
27
+ * - progress bars
28
+ * - spinners
29
+ * - prompts
30
+ * - stylized output (JSON, url, objects, headers)
31
+ * - lifecycle events
32
+ * - configuration variables help section
33
+ * - environment variables help section
34
+ * - error codes help section
27
35
  *
28
- * @extends @oclif/core/command
29
- * @see https://github.com/oclif/core/blob/main/src/command.ts
36
+ * All implementations of this class need to implement the run() method.
37
+ *
38
+ * Additionally, all implementations of this class need to provide a generic type that describes the JSON output.
39
+ *
40
+ * See {@link https://github.com/salesforcecli/plugin-template-sf/blob/main/src/commands/hello/world.ts example implementation}.
41
+ *
42
+ * @example
43
+ *
44
+ * ```
45
+ * import { SfCommand } from '@salesforce/sf-plugins-core';
46
+ * export type MyJsonOutput = { success: boolean };
47
+ * export default class MyCommand extends SfCommand<MyJsonOutput> {
48
+ * public async run(): Promise<MyJsonOutput> {
49
+ * return { success: true };
50
+ * }
51
+ * }
52
+ * ```
30
53
  */
31
54
  class SfCommand extends core_1.Command {
32
55
  constructor(argv, config) {
@@ -43,40 +66,43 @@ class SfCommand extends core_1.Command {
43
66
  return this.constructor;
44
67
  }
45
68
  /**
46
- * Log a success message that has the standard success message color applied
69
+ * Log a success message that has the standard success message color applied.
47
70
  *
48
- * @param message
49
- * @param args
71
+ * @param message The message to log.
50
72
  */
51
73
  logSuccess(message) {
52
74
  this.log(exports.StandardColors.success(message));
53
75
  }
54
76
  /**
55
- * Log warning to users. If --json is enabled, then the warning
56
- * will be added to the json output under the warnings property.
77
+ * Log warning to users. If --json is enabled, then the warning will be added to the json output under the warnings property.
78
+ *
79
+ * @param input {@link SfCommand.Warning} The message to log.
57
80
  */
58
81
  warn(input) {
59
82
  const colorizedArgs = [];
60
83
  this.warnings.push(input);
61
84
  const message = typeof input === 'string' ? input : input.message;
62
85
  colorizedArgs.push(`${exports.StandardColors.warning(messages.getMessage('warning.prefix'))} ${message}`);
63
- colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: exports.StandardColors.info }));
86
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: exports.StandardColors.info }));
64
87
  this.log(colorizedArgs.join(os.EOL));
65
88
  return input;
66
89
  }
67
90
  /**
68
91
  * Log info message to users.
92
+ *
93
+ * @param input {@link SfCommand.Info} The message to log.
69
94
  */
70
95
  info(input) {
71
96
  const colorizedArgs = [];
72
97
  const message = typeof input === 'string' ? input : input.message;
73
98
  colorizedArgs.push(`${exports.StandardColors.info(message)}`);
74
- colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: exports.StandardColors.info }));
99
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions ?? [], { actionColor: exports.StandardColors.info }));
75
100
  this.log(colorizedArgs.join(os.EOL));
76
101
  }
77
102
  /**
78
- * Warn user about sensitive information (access tokens, etc...) before
79
- * logging to the console.
103
+ * Warn user about sensitive information (access tokens, etc...) before logging to the console.
104
+ *
105
+ * @param msg The message to log.
80
106
  */
81
107
  logSensitive(msg) {
82
108
  this.warn(messages.getMessage('warning.security'));
@@ -90,24 +116,33 @@ class SfCommand extends core_1.Command {
90
116
  }
91
117
  /**
92
118
  * Log a stylized url to the console. Will automatically be suppressed when --json flag is present.
119
+ *
120
+ * @param text The text to display for the url.
121
+ * @param uri The url to display.
93
122
  */
94
123
  url(text, uri, params = {}) {
95
124
  this.ux.url(text, uri, params);
96
125
  }
97
126
  /**
98
127
  * Log stylized JSON to the console. Will automatically be suppressed when --json flag is present.
128
+ *
129
+ * @param obj The JSON to log.
99
130
  */
100
131
  styledJSON(obj) {
101
132
  this.ux.styledJSON(obj);
102
133
  }
103
134
  /**
104
135
  * Log stylized object to the console. Will automatically be suppressed when --json flag is present.
136
+ *
137
+ * @param obj The object to log.
105
138
  */
106
139
  styledObject(obj) {
107
140
  this.ux.styledObject(obj);
108
141
  }
109
142
  /**
110
143
  * Log stylized header to the console. Will automatically be suppressed when --json flag is present.
144
+ *
145
+ * @param text the text to display as a header.
111
146
  */
112
147
  styledHeader(text) {
113
148
  this.ux.styledHeader(text);
@@ -129,7 +164,7 @@ class SfCommand extends core_1.Command {
129
164
  return this.prompter.prompt(questions, initialAnswers);
130
165
  }
131
166
  /**
132
- * Simplified prompt for single-question confirmation. Times out and throws after 10s
167
+ * Simplified prompt for single-question confirmation. Times out and throws after 10s
133
168
  *
134
169
  * @param message text to display. Do not include a question mark.
135
170
  * @param ms milliseconds to wait for user input. Defaults to 10s.
@@ -167,9 +202,8 @@ class SfCommand extends core_1.Command {
167
202
  * Wrap the command result into the standardized JSON structure.
168
203
  */
169
204
  toSuccessJson(result) {
170
- var _a;
171
205
  return {
172
- status: (_a = process.exitCode) !== null && _a !== void 0 ? _a : 0,
206
+ status: process.exitCode ?? 0,
173
207
  result,
174
208
  warnings: this.warnings,
175
209
  };
@@ -183,6 +217,7 @@ class SfCommand extends core_1.Command {
183
217
  warnings: this.warnings,
184
218
  };
185
219
  }
220
+ // eslint-disable-next-line class-methods-use-this
186
221
  async assignProject() {
187
222
  try {
188
223
  return await core_2.SfProject.resolve();
@@ -195,10 +230,9 @@ class SfCommand extends core_1.Command {
195
230
  }
196
231
  }
197
232
  async catch(error) {
198
- var _a, _b;
199
233
  // transform an unknown error into one that conforms to the interface
200
234
  const codeFromError = error instanceof core_2.SfError ? error.exitCode : 1;
201
- (_a = process.exitCode) !== null && _a !== void 0 ? _a : (process.exitCode = codeFromError);
235
+ process.exitCode ?? (process.exitCode = codeFromError);
202
236
  const sfErrorProperties = error instanceof core_2.SfError
203
237
  ? { data: error.data, actions: error.actions, code: codeFromError, context: error.context }
204
238
  : {};
@@ -206,7 +240,7 @@ class SfCommand extends core_1.Command {
206
240
  ...sfErrorProperties,
207
241
  ...{
208
242
  message: error.message,
209
- name: (_b = error.name) !== null && _b !== void 0 ? _b : 'Error',
243
+ name: error.name ?? 'Error',
210
244
  status: process.exitCode,
211
245
  stack: error.stack,
212
246
  exitCode: process.exitCode,
@@ -234,7 +268,7 @@ class SfCommand extends core_1.Command {
234
268
  const errorCode = error.code ? ` (${error.code})` : '';
235
269
  const errorPrefix = `${exports.StandardColors.error(messages.getMessage('error.prefix', [errorCode]))}`;
236
270
  colorizedArgs.push(`${errorPrefix} ${error.message}`);
237
- colorizedArgs.push(...this.formatActions(error.actions || []));
271
+ colorizedArgs.push(...this.formatActions(error.actions ?? []));
238
272
  if (error.stack && core_2.envVars.getString(SfCommand.SF_ENV) === core_2.Mode.DEVELOPMENT) {
239
273
  colorizedArgs.push(exports.StandardColors.info(`\n*** Internal Diagnostic ***\n\n${error.stack}\n******\n`));
240
274
  }
@@ -247,10 +281,11 @@ class SfCommand extends core_1.Command {
247
281
  * @param options
248
282
  * @private
249
283
  */
284
+ // eslint-disable-next-line class-methods-use-this
250
285
  formatActions(actions, options = { actionColor: exports.StandardColors.info }) {
251
286
  const colorizedArgs = [];
252
287
  // Format any actions.
253
- if (actions === null || actions === void 0 ? void 0 : actions.length) {
288
+ if (actions?.length) {
254
289
  colorizedArgs.push(`\n${exports.StandardColors.info(messages.getMessage('actions.tryThis'))}\n`);
255
290
  actions.forEach((action) => {
256
291
  colorizedArgs.push(`${options.actionColor(action)}`);
@@ -262,5 +297,19 @@ class SfCommand extends core_1.Command {
262
297
  exports.SfCommand = SfCommand;
263
298
  SfCommand.SF_ENV = 'SF_ENV';
264
299
  SfCommand.enableJsonFlag = true;
300
+ /**
301
+ * Flags that you can use for manipulating tables.
302
+ *
303
+ * @example
304
+ * ```
305
+ * import { SfCommand } from '@salesforce/sf-plugins-core';
306
+ * export default class MyCommand extends SfCommand {
307
+ * public static flags = {
308
+ * ...SfCommand.tableFags,
309
+ * 'my-flags: flags.string({ char: 'm', description: 'my flag' }),
310
+ * }
311
+ * }
312
+ * ```
313
+ */
265
314
  SfCommand.tableFlags = core_1.CliUx.ux.table.flags;
266
315
  //# sourceMappingURL=sfCommand.js.map
@@ -9,13 +9,18 @@ export declare type JsonObject = {
9
9
  * you can specify how a key should be displayed to the user.
10
10
  *
11
11
  * @example
12
+ *
13
+ * ```
12
14
  * { data: { theURL: 'https://example.com' } }
13
15
  * // Renders as:
14
16
  * Key Value
15
17
  * ------- -------------------
16
18
  * The URL https://example.com
19
+ * ```
17
20
  *
18
21
  * @example
22
+ *
23
+ * ```
19
24
  * {
20
25
  * data: { theURL: 'https://example.com' }
21
26
  * keys: { theURL: 'Url' },
@@ -24,11 +29,13 @@ export declare type JsonObject = {
24
29
  * Key Value
25
30
  * --- -------------------
26
31
  * Url https://example.com
27
- *
32
+ *```
28
33
  * If no environment matches the provided targetEnv, then return null in the data field.
29
34
  *
30
35
  * @example
36
+ * ```
31
37
  * { data: null }
38
+ * ```
32
39
  */
33
40
  export declare namespace EnvDisplay {
34
41
  type Keys<T> = Record<keyof T, string>;
@@ -50,6 +57,8 @@ export declare namespace EnvDisplay {
50
57
  * the `keys` property.
51
58
  *
52
59
  * @example
60
+ *
61
+ * ```
53
62
  * {
54
63
  * title: 'My Envs',
55
64
  * data: [{ username: 'foo', theURL: 'https://example.com' }]
@@ -59,8 +68,11 @@ export declare namespace EnvDisplay {
59
68
  * ================================
60
69
  * | Username | The URL
61
70
  * | foo | https://example.com
71
+ *```
62
72
  *
63
73
  * @example
74
+ *
75
+ * ```
64
76
  * {
65
77
  * data: [{ username: 'foo', theURL: 'https://example.com' }]
66
78
  * keys: { theURL: 'Url', username: 'Name' },
@@ -71,6 +83,8 @@ export declare namespace EnvDisplay {
71
83
  * ============================
72
84
  * | Name | Url
73
85
  * | foo | https://example.com
86
+ *
87
+ *```
74
88
  */
75
89
  export declare namespace EnvList {
76
90
  export enum EnvType {
@@ -14,6 +14,8 @@ exports.EnvList = void 0;
14
14
  * the `keys` property.
15
15
  *
16
16
  * @example
17
+ *
18
+ * ```
17
19
  * {
18
20
  * title: 'My Envs',
19
21
  * data: [{ username: 'foo', theURL: 'https://example.com' }]
@@ -23,8 +25,11 @@ exports.EnvList = void 0;
23
25
  * ================================
24
26
  * | Username | The URL
25
27
  * | foo | https://example.com
28
+ *```
26
29
  *
27
30
  * @example
31
+ *
32
+ * ```
28
33
  * {
29
34
  * data: [{ username: 'foo', theURL: 'https://example.com' }]
30
35
  * keys: { theURL: 'Url', username: 'Name' },
@@ -35,6 +40,8 @@ exports.EnvList = void 0;
35
40
  * ============================
36
41
  * | Name | Url
37
42
  * | foo | https://example.com
43
+ *
44
+ *```
38
45
  */
39
46
  var EnvList;
40
47
  (function (EnvList) {
package/lib/util.d.ts CHANGED
@@ -16,4 +16,5 @@ export declare type HelpSection = {
16
16
  * @param vars
17
17
  */
18
18
  export declare function toHelpSection(header: string, ...vars: Array<OrgConfigProperties | SfdxPropertyKeys | EnvironmentVariable | string | Record<string, string>>): HelpSection;
19
+ export declare function parseVarArgs(args: Record<string, unknown>, argv: string[]): Record<string, unknown>;
19
20
  //# sourceMappingURL=util.d.ts.map
package/lib/util.js CHANGED
@@ -6,8 +6,10 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.toHelpSection = void 0;
9
+ exports.parseVarArgs = exports.toHelpSection = void 0;
10
10
  const core_1 = require("@salesforce/core");
11
+ core_1.Messages.importMessagesDirectory(__dirname);
12
+ const messages = core_1.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
11
13
  /**
12
14
  * Function to build a help section for command help.
13
15
  * Takes a string to be used as section header text and an array of enums
@@ -21,9 +23,7 @@ function toHelpSection(header, ...vars) {
21
23
  const body = vars
22
24
  .flatMap((v) => {
23
25
  if (typeof v === 'string') {
24
- const orgConfig = core_1.ORG_CONFIG_ALLOWED_PROPERTIES.find(({ key }) => {
25
- return key === v;
26
- });
26
+ const orgConfig = core_1.ORG_CONFIG_ALLOWED_PROPERTIES.find(({ key }) => key === v);
27
27
  if (orgConfig) {
28
28
  return { name: orgConfig.key, description: orgConfig.description };
29
29
  }
@@ -46,4 +46,28 @@ function toHelpSection(header, ...vars) {
46
46
  return { header, body };
47
47
  }
48
48
  exports.toHelpSection = toHelpSection;
49
+ function parseVarArgs(args, argv) {
50
+ const final = {};
51
+ const argVals = Object.values(args);
52
+ // Remove arguments from varargs
53
+ const varargs = argv.filter((val) => !argVals.includes(val));
54
+ // Support `config set key value`
55
+ if (varargs.length === 2 && !varargs[0].includes('=')) {
56
+ return { [varargs[0]]: varargs[1] };
57
+ }
58
+ // Ensure that all args are in the right format (e.g. key=value key1=value1)
59
+ varargs.forEach((arg) => {
60
+ const split = arg.split('=');
61
+ if (split.length !== 2) {
62
+ throw messages.createError('error.InvalidArgumentFormat', [arg]);
63
+ }
64
+ const [name, value] = split;
65
+ if (final[name]) {
66
+ throw messages.createError('error.DuplicateArgument', [name]);
67
+ }
68
+ final[name] = value || undefined;
69
+ });
70
+ return final;
71
+ }
72
+ exports.parseVarArgs = parseVarArgs;
49
73
  //# sourceMappingURL=util.js.map
@@ -4,24 +4,27 @@ export declare class Prompter {
4
4
  /**
5
5
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
6
6
  */
7
- prompt<T = Prompter.Answers>(questions: Prompter.Questions<T>, initialAnswers?: Partial<T>): Promise<T>;
7
+ prompt<T extends Prompter.Answers>(questions: Prompter.Questions<T>, initialAnswers?: Partial<T>): Promise<T>;
8
8
  /**
9
9
  * Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
10
10
  */
11
- timedPrompt<T = Prompter.Answers>(questions: Prompter.Questions<T>, ms?: number, initialAnswers?: Partial<T>): Promise<T>;
11
+ timedPrompt<T extends Prompter.Answers>(questions: Prompter.Questions<T>, ms?: number, initialAnswers?: Partial<T>): Promise<T>;
12
12
  }
13
13
  export declare namespace Prompter {
14
14
  type Answers<T = Record<string, unknown>> = T & Record<string, unknown>;
15
- type Questions<T> = QuestionCollection<T>;
15
+ type Questions<T extends Answers> = QuestionCollection<T>;
16
16
  }
17
17
  /**
18
18
  * Generate a formatted table for list and checkbox prompts
19
19
  *
20
20
  * Each option should contain the same keys as specified in columns.
21
- * For example,
21
+ *
22
+ * @example
23
+ * ```
22
24
  * const columns = { name: 'Name', type: 'Type', path: 'Path' };
23
25
  * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
24
26
  * generateTableChoices(columns, options);
27
+ * ```
25
28
  */
26
29
  export declare function generateTableChoices<T>(columns: Dictionary<string>, choices: Array<Dictionary<Nullable<string> | T>>, padForCheckbox?: boolean): ChoiceBase[];
27
30
  //# sourceMappingURL=prompter.d.ts.map
@@ -14,6 +14,7 @@ class Prompter {
14
14
  /**
15
15
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
16
16
  */
17
+ // eslint-disable-next-line class-methods-use-this
17
18
  async prompt(questions, initialAnswers) {
18
19
  const answers = await (0, inquirer_1.prompt)(questions, initialAnswers);
19
20
  return answers;
@@ -21,6 +22,7 @@ class Prompter {
21
22
  /**
22
23
  * Prompt user for information with a timeout (in milliseconds). See https://www.npmjs.com/package/inquirer for more.
23
24
  */
25
+ // eslint-disable-next-line class-methods-use-this
24
26
  async timedPrompt(questions, ms = 10000, initialAnswers) {
25
27
  let id;
26
28
  const thePrompt = (0, inquirer_1.prompt)(questions, initialAnswers);
@@ -45,10 +47,13 @@ exports.Prompter = Prompter;
45
47
  * Generate a formatted table for list and checkbox prompts
46
48
  *
47
49
  * Each option should contain the same keys as specified in columns.
48
- * For example,
50
+ *
51
+ * @example
52
+ * ```
49
53
  * const columns = { name: 'Name', type: 'Type', path: 'Path' };
50
54
  * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
51
55
  * generateTableChoices(columns, options);
56
+ * ```
52
57
  */
53
58
  function generateTableChoices(columns, choices,
54
59
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -58,7 +63,7 @@ padForCheckbox = true) {
58
63
  .length)) + 1);
59
64
  const choicesOptions = [
60
65
  new inquirer_1.Separator(`${padForCheckbox ? ' '.repeat(2) : ''}${columnEntries
61
- .map(([, value], index) => value === null || value === void 0 ? void 0 : value.padEnd(columnLengths[index], ' '))
66
+ .map(([, value], index) => value?.padEnd(columnLengths[index], ' '))
62
67
  .join('')}`),
63
68
  ];
64
69
  for (const meta of choices) {
@@ -5,6 +5,14 @@ import { UxBase } from '.';
5
5
  */
6
6
  export declare class Spinner extends UxBase {
7
7
  constructor(outputEnabled: boolean);
8
+ /**
9
+ * Get the status of the current spinner.
10
+ */
11
+ get status(): string | undefined;
12
+ /**
13
+ * Set the status of the current spinner.
14
+ */
15
+ set status(status: string | undefined);
8
16
  /**
9
17
  * Start a spinner on the console.
10
18
  */
@@ -15,14 +23,6 @@ export declare class Spinner extends UxBase {
15
23
  * Stop the spinner on the console.
16
24
  */
17
25
  stop(msg?: string): void;
18
- /**
19
- * Set the status of the current spinner.
20
- */
21
- set status(status: string | undefined);
22
- /**
23
- * Get the status of the current spinner.
24
- */
25
- get status(): string | undefined;
26
26
  /**
27
27
  * Pause the spinner on the console.
28
28
  */