@@ -80,8 +80,9 @@ export async function deployTarget(
8080 await printAndRun ( rsyncCommand ) ;
8181 } catch ( e ) {
8282 if (
83- await askYesNoWithDefaultYes (
83+ await askYesNo (
8484 "Deployment failed. Try again by creating folder on the server?" ,
85+ { default : "y" } ,
8586 )
8687 ) {
8788 await printAndRun ( sshMkdirCommand ) ;
@@ -99,15 +100,29 @@ Successfully deployed:
99100` ) ;
100101}
101102
102- async function askYesNoWithDefaultYes ( question : string ) : Promise < boolean > {
103- const readline = ( await import ( "node:readline" ) ) . createInterface ( {
104- input : process . stdin ,
105- output : process . stdout ,
106- } ) ;
107- const q = ( await import ( "node:util" ) )
108- . promisify ( readline . question )
109- . bind ( readline ) as unknown as ( question : string ) => Promise < string > ;
110- const response : string = await q ( `${ question } (Y/n) ` ) ;
111- readline . close ( ) ;
112- return response . toLowerCase ( ) === "y" ;
103+ async function askYesNo (
104+ question : string ,
105+ options ?: { default ?: "y" | "n" } ,
106+ ) : Promise < boolean > {
107+ function letter ( c : string ) {
108+ return options ?. default === c ? c . toUpperCase ( ) : c ;
109+ }
110+ while ( true ) {
111+ const readline = ( await import ( "node:readline" ) ) . createInterface ( {
112+ input : process . stdin ,
113+ output : process . stdout ,
114+ } ) ;
115+ const q = ( await import ( "node:util" ) )
116+ . promisify ( readline . question )
117+ . bind ( readline ) as unknown as ( question : string ) => Promise < string > ;
118+ const yn = `${ letter ( "y" ) } /${ letter ( "n" ) } ` ;
119+ const response : string = await q ( `${ question } (${ yn } ) ` ) ;
120+ readline . close ( ) ;
121+ if ( response . toLowerCase ( ) || options ?. default === "y" ) {
122+ return true ;
123+ }
124+ if ( response . toLowerCase ( ) || options ?. default === "n" ) {
125+ return false ;
126+ }
127+ }
113128}
0 commit comments