@@ -14,45 +14,34 @@ export class Prompter implements IPrompter {
14
14
}
15
15
}
16
16
17
- public async get ( schemas : IPromptSchema [ ] ) : Promise < any > {
18
- let promptResult : any ;
19
-
17
+ public async get ( questions : prompt . Question [ ] ) : Promise < any > {
20
18
try {
21
- promptResult = await new Promise < any > ( ( resolve , reject ) => {
22
19
this . muteStdout ( ) ;
23
20
24
21
if ( ! helpers . isInteractive ( ) ) {
25
- if ( _ . some ( schemas , s => ! s . default ) ) {
26
- reject ( new Error ( "Console is not interactive and no default action specified." ) ) ;
22
+ if ( _ . some ( questions , s => ! s . default ) ) {
23
+ throw new Error ( "Console is not interactive and no default action specified." ) ;
27
24
} else {
28
25
const result : any = { } ;
29
26
30
- _ . each ( schemas , s => {
27
+ _ . each ( questions , s => {
31
28
// Curly brackets needed because s.default() may return false and break the loop
32
29
result [ s . name ] = s . default ( ) ;
33
30
} ) ;
34
31
35
- resolve ( result ) ;
32
+ return result ;
36
33
}
37
34
} else {
38
- prompt . prompt ( schemas , ( result : any ) => {
39
- if ( result ) {
40
- resolve ( result ) ;
41
- } else {
42
- reject ( new Error ( `Unable to get result from prompt: ${ result } ` ) ) ;
43
- }
44
- } ) ;
35
+ const result = await prompt . prompt ( questions ) ;
36
+ return result ;
45
37
}
46
- } ) ;
47
38
} finally {
48
39
this . unmuteStdout ( ) ;
49
40
}
50
-
51
- return promptResult ;
52
41
}
53
42
54
43
public async getPassword ( prompt : string , options ?: IAllowEmpty ) : Promise < string > {
55
- const schema : IPromptSchema = {
44
+ const schema : prompt . Question = {
56
45
message : prompt ,
57
46
type : "password" ,
58
47
name : "password" ,
@@ -67,7 +56,7 @@ export class Prompter implements IPrompter {
67
56
}
68
57
69
58
public async getString ( prompt : string , options ?: IPrompterOptions ) : Promise < string > {
70
- const schema : IPromptSchema = {
59
+ const schema : prompt . Question = {
71
60
message : prompt ,
72
61
type : "input" ,
73
62
name : "inputString" ,
@@ -83,7 +72,7 @@ export class Prompter implements IPrompter {
83
72
}
84
73
85
74
public async promptForChoice ( promptMessage : string , choices : any [ ] ) : Promise < string > {
86
- const schema : IPromptSchema = {
75
+ const schema : prompt . Question = {
87
76
message : promptMessage ,
88
77
type : "list" ,
89
78
name : "userAnswer" ,
0 commit comments