Skip to content

Commit e4a7ef4

Browse files
authored
refactor: move confirm to Prompter so it can be on Ux export (#154)
1 parent 05285d9 commit e4a7ef4

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/sfCommand.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,7 @@ export abstract class SfCommand<T> extends Command {
336336
* @return true if the user confirms, false if they do not.
337337
*/
338338
public async confirm(message: string, ms = 10000): Promise<boolean> {
339-
const { confirmed } = await this.timedPrompt<{ confirmed: boolean }>(
340-
[
341-
{
342-
name: 'confirmed',
343-
message,
344-
type: 'confirm',
345-
},
346-
],
347-
ms
348-
);
349-
return confirmed;
339+
return this.prompter.confirm(message, ms);
350340
}
351341

352342
/**

src/ux/prompter.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ export class Prompter {
4949
return result as T;
5050
});
5151
}
52+
53+
/**
54+
* Simplified prompt for single-question confirmation. Times out and throws after 10s
55+
*
56+
* @param message text to display. Do not include a question mark.
57+
* @param ms milliseconds to wait for user input. Defaults to 10s.
58+
* @return true if the user confirms, false if they do not.
59+
*/
60+
public async confirm(message: string, ms = 10000): Promise<boolean> {
61+
const { confirmed } = await this.timedPrompt<{ confirmed: boolean }>(
62+
[
63+
{
64+
name: 'confirmed',
65+
message,
66+
type: 'confirm',
67+
},
68+
],
69+
ms
70+
);
71+
return confirmed;
72+
}
5273
}
5374

5475
export namespace Prompter {

0 commit comments

Comments
 (0)