forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.ts
74 lines (64 loc) · 1.48 KB
/
prompt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { isTTY } from './tty';
export async function askConfirmation(
message: string,
defaultResponse: boolean,
noTTYResponse?: boolean,
): Promise<boolean> {
if (!isTTY()) {
return noTTYResponse ?? defaultResponse;
}
const { confirm } = await import('@inquirer/prompts');
const answer = await confirm({
message,
default: defaultResponse,
theme: {
prefix: '',
},
});
return answer;
}
export async function askQuestion(
message: string,
choices: { name: string; value: string | null }[],
defaultResponseIndex: number,
noTTYResponse: null | string,
): Promise<string | null> {
if (!isTTY()) {
return noTTYResponse;
}
const { select } = await import('@inquirer/prompts');
const answer = await select({
message,
choices,
default: defaultResponseIndex,
theme: {
prefix: '',
},
});
return answer;
}
export async function askChoices(
message: string,
choices: { name: string; value: string; checked?: boolean }[],
noTTYResponse: string[] | null,
): Promise<string[] | null> {
if (!isTTY()) {
return noTTYResponse;
}
const { checkbox } = await import('@inquirer/prompts');
const answers = await checkbox({
message,
choices,
theme: {
prefix: '',
},
});
return answers;
}