1- // @ts -types="@types/prompts"
2- import prompt from "prompts" ;
1+ import { promptMultipleSelect } from "@std/cli/unstable-prompt-multiple-select" ;
32
43import { gray , green , yellow } from "@std/fmt/colors" ;
54import { createTrpcClient } from "../auth.ts" ;
@@ -181,34 +180,30 @@ export async function setupAws(
181180 log ( "\r" ) ;
182181
183182 const choices = allPolicies . Policies . map ( ( policy ) => ( {
184- title : policy . PolicyName ,
183+ label : policy . PolicyName ,
185184 value : policy . Arn ,
186185 } ) ) ;
187186
188187 let policies ;
189188 while ( true ) {
190- const result = await prompt ( {
191- type : "autocompleteMultiselect" ,
192- name : "policies" ,
193- message : "Select permission policies you want to attach to the new role" ,
189+ const result = promptMultipleSelect (
190+ "Select permission policies you want to attach to the new role" ,
194191 choices ,
195- hint : "- Space to select a policy, Enter to confirm your selections" ,
196- instructions : false ,
197- } ) ;
192+ {
193+ clear : true ,
194+ fitToRemainingHeight : true ,
195+ } ,
196+ ) ;
198197
199- if ( result . policies === undefined ) {
198+ if ( result === null ) {
200199 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
201200 Deno . exit ( 1 ) ;
202201 }
203202
204- if ( result . policies . length === 0 ) {
205- const { confirmNoPolicies } = await prompt ( {
206- type : "confirm" ,
207- name : "confirmNoPolicies" ,
208- message :
209- "Are you sure you don't want to associate any policies? Remember to use Space to select a policy, and Enter to confirm your selections." ,
210- initial : false ,
211- } ) ;
203+ if ( result . length === 0 ) {
204+ const confirmNoPolicies = confirm (
205+ "Are you sure you don't want to associate any policies? Remember to use Space to select a policy, and Enter to confirm your selections." ,
206+ ) ;
212207 if ( ! confirmNoPolicies ) {
213208 continue ;
214209 }
@@ -218,7 +213,7 @@ export async function setupAws(
218213 ) ;
219214 }
220215
221- policies = result . policies ;
216+ policies = result ;
222217 break ;
223218 }
224219
@@ -290,13 +285,7 @@ export async function setupAws(
290285
291286 console . log ( "" ) ;
292287
293- const { confirm } = await prompt ( {
294- type : "confirm" ,
295- name : "confirm" ,
296- message : "Do you want to apply these changes?" ,
297- initial : true ,
298- } ) ;
299- if ( ! confirm ) {
288+ if ( ! confirm ( "Do you want to apply these changes?" ) ) {
300289 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
301290 Deno . exit ( 1 ) ;
302291 }
@@ -390,7 +379,7 @@ export async function setupAws(
390379 "--role-name" ,
391380 roleName ,
392381 "--policy-arn" ,
393- policy ,
382+ policy . value ,
394383 ] ) ;
395384 }
396385 console . log (
@@ -510,12 +499,7 @@ export async function setupGcp(
510499 }
511500 console . log ( "" ) ;
512501
513- const { enableApis } = await prompt ( {
514- type : "confirm" ,
515- name : "enableApis" ,
516- message : "Do you want to enable these APIs now?" ,
517- initial : true ,
518- } ) ;
502+ const enableApis = confirm ( "Do you want to enable these APIs now?" ) ;
519503
520504 if ( ! enableApis ) {
521505 console . log (
@@ -592,34 +576,30 @@ export async function setupGcp(
592576 log ( "\r" ) ;
593577
594578 const roleChoices = roles . map ( ( role ) => ( {
595- title : `${ role . title } (${ role . name . split ( "/" ) . pop ( ) } )` ,
579+ label : `${ role . title } (${ role . name . split ( "/" ) . pop ( ) } )` ,
596580 value : role . name ,
597581 } ) ) ;
598582
599583 let selectedRoles ;
600584 while ( true ) {
601- const result = await prompt ( {
602- type : "autocompleteMultiselect ",
603- name : "selectedRoles" ,
604- message : "Select IAM roles you want to grant to the service account" ,
605- choices : roleChoices ,
606- hint : "- Space to select a role, Enter to confirm your selections" ,
607- instructions : false ,
608- } ) ;
609-
610- if ( result . selectedRoles === undefined ) {
585+ const result = promptMultipleSelect (
586+ "Select IAM roles you want to grant to the service account ",
587+ roleChoices ,
588+ {
589+ clear : true ,
590+ fitToRemainingHeight : true ,
591+ } ,
592+ ) ;
593+
594+ if ( result === null ) {
611595 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
612596 Deno . exit ( 1 ) ;
613597 }
614598
615- if ( result . selectedRoles . length === 0 ) {
616- const { confirmNoRoles } = await prompt ( {
617- type : "confirm" ,
618- name : "confirmNoRoles" ,
619- message :
620- "Are you sure you don't want to associate any roles? Remember to use Space to select a role, and Enter to confirm your selections." ,
621- initial : false ,
622- } ) ;
599+ if ( result . length === 0 ) {
600+ const confirmNoRoles = confirm (
601+ "Are you sure you don't want to associate any roles? Remember to use Space to select a role, and Enter to confirm your selections." ,
602+ ) ;
623603 if ( ! confirmNoRoles ) {
624604 continue ;
625605 }
@@ -629,7 +609,7 @@ export async function setupGcp(
629609 ) ;
630610 }
631611
632- selectedRoles = result . selectedRoles ;
612+ selectedRoles = result ;
633613 break ;
634614 }
635615
@@ -704,7 +684,7 @@ export async function setupGcp(
704684 ) ;
705685
706686 for ( const role of selectedRoles ) {
707- const roleName = role . split ( "/" ) . pop ( ) ;
687+ const roleName = role . value . split ( "/" ) . pop ( ) ;
708688 console . log (
709689 ` %c+ grant%c role %c${ roleName } %c to the service account` ,
710690 "color: green;" ,
@@ -716,14 +696,7 @@ export async function setupGcp(
716696
717697 console . log ( "" ) ;
718698
719- const { confirm } = await prompt ( {
720- type : "confirm" ,
721- name : "confirm" ,
722- message : "Do you want to apply these changes?" ,
723- initial : true ,
724- } ) ;
725-
726- if ( ! confirm ) {
699+ if ( ! confirm ( "Do you want to apply these changes?" ) ) {
727700 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
728701 Deno . exit ( 1 ) ;
729702 }
0 commit comments