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" ;
@@ -183,34 +182,30 @@ export async function setupAws(
183182 log ( "\r" ) ;
184183
185184 const choices = allPolicies . Policies . map ( ( policy ) => ( {
186- title : policy . PolicyName ,
185+ label : policy . PolicyName ,
187186 value : policy . Arn ,
188187 } ) ) ;
189188
190189 let policies ;
191190 while ( true ) {
192- const result = await prompt ( {
193- type : "autocompleteMultiselect" ,
194- name : "policies" ,
195- message : "Select permission policies you want to attach to the new role" ,
191+ const result = promptMultipleSelect (
192+ "Select permission policies you want to attach to the new role" ,
196193 choices ,
197- hint : "- Space to select a policy, Enter to confirm your selections" ,
198- instructions : false ,
199- } ) ;
194+ {
195+ clear : true ,
196+ fitToRemainingHeight : true ,
197+ } ,
198+ ) ;
200199
201- if ( result . policies === undefined ) {
200+ if ( result === null ) {
202201 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
203202 Deno . exit ( 1 ) ;
204203 }
205204
206- if ( result . policies . length === 0 ) {
207- const { confirmNoPolicies } = await prompt ( {
208- type : "confirm" ,
209- name : "confirmNoPolicies" ,
210- message :
211- "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." ,
212- initial : false ,
213- } ) ;
205+ if ( result . length === 0 ) {
206+ const confirmNoPolicies = confirm (
207+ "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." ,
208+ ) ;
214209 if ( ! confirmNoPolicies ) {
215210 continue ;
216211 }
@@ -220,7 +215,7 @@ export async function setupAws(
220215 ) ;
221216 }
222217
223- policies = result . policies ;
218+ policies = result ;
224219 break ;
225220 }
226221
@@ -292,13 +287,7 @@ export async function setupAws(
292287
293288 console . log ( "" ) ;
294289
295- const { confirm } = await prompt ( {
296- type : "confirm" ,
297- name : "confirm" ,
298- message : "Do you want to apply these changes?" ,
299- initial : true ,
300- } ) ;
301- if ( ! confirm ) {
290+ if ( ! confirm ( "Do you want to apply these changes?" ) ) {
302291 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
303292 Deno . exit ( 1 ) ;
304293 }
@@ -392,7 +381,7 @@ export async function setupAws(
392381 "--role-name" ,
393382 roleName ,
394383 "--policy-arn" ,
395- policy ,
384+ policy . value ,
396385 ] ) ;
397386 }
398387 console . log (
@@ -514,12 +503,7 @@ export async function setupGcp(
514503 }
515504 console . log ( "" ) ;
516505
517- const { enableApis } = await prompt ( {
518- type : "confirm" ,
519- name : "enableApis" ,
520- message : "Do you want to enable these APIs now?" ,
521- initial : true ,
522- } ) ;
506+ const enableApis = confirm ( "Do you want to enable these APIs now?" ) ;
523507
524508 if ( ! enableApis ) {
525509 console . log (
@@ -596,34 +580,30 @@ export async function setupGcp(
596580 log ( "\r" ) ;
597581
598582 const roleChoices = roles . map ( ( role ) => ( {
599- title : `${ role . title } (${ role . name . split ( "/" ) . pop ( ) } )` ,
583+ label : `${ role . title } (${ role . name . split ( "/" ) . pop ( ) } )` ,
600584 value : role . name ,
601585 } ) ) ;
602586
603587 let selectedRoles ;
604588 while ( true ) {
605- const result = await prompt ( {
606- type : "autocompleteMultiselect ",
607- name : "selectedRoles" ,
608- message : "Select IAM roles you want to grant to the service account" ,
609- choices : roleChoices ,
610- hint : "- Space to select a role, Enter to confirm your selections" ,
611- instructions : false ,
612- } ) ;
589+ const result = promptMultipleSelect (
590+ "Select IAM roles you want to grant to the service account ",
591+ roleChoices ,
592+ {
593+ clear : true ,
594+ fitToRemainingHeight : true ,
595+ } ,
596+ ) ;
613597
614- if ( result . selectedRoles === undefined ) {
598+ if ( result === null ) {
615599 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
616600 Deno . exit ( 1 ) ;
617601 }
618602
619- if ( result . selectedRoles . length === 0 ) {
620- const { confirmNoRoles } = await prompt ( {
621- type : "confirm" ,
622- name : "confirmNoRoles" ,
623- message :
624- "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." ,
625- initial : false ,
626- } ) ;
603+ if ( result . length === 0 ) {
604+ const confirmNoRoles = confirm (
605+ "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." ,
606+ ) ;
627607 if ( ! confirmNoRoles ) {
628608 continue ;
629609 }
@@ -633,7 +613,7 @@ export async function setupGcp(
633613 ) ;
634614 }
635615
636- selectedRoles = result . selectedRoles ;
616+ selectedRoles = result ;
637617 break ;
638618 }
639619
@@ -708,7 +688,7 @@ export async function setupGcp(
708688 ) ;
709689
710690 for ( const role of selectedRoles ) {
711- const roleName = role . split ( "/" ) . pop ( ) ;
691+ const roleName = role . value . split ( "/" ) . pop ( ) ;
712692 console . log (
713693 ` %c+ grant%c role %c${ roleName } %c to the service account` ,
714694 "color: green;" ,
@@ -720,14 +700,7 @@ export async function setupGcp(
720700
721701 console . log ( "" ) ;
722702
723- const { confirm } = await prompt ( {
724- type : "confirm" ,
725- name : "confirm" ,
726- message : "Do you want to apply these changes?" ,
727- initial : true ,
728- } ) ;
729-
730- if ( ! confirm ) {
703+ if ( ! confirm ( "Do you want to apply these changes?" ) ) {
731704 console . log ( "%c Exiting setup." , "color: yellow;" ) ;
732705 Deno . exit ( 1 ) ;
733706 }
0 commit comments