@@ -2,10 +2,9 @@ import inquirer from "inquirer";
22import autocomplete from "inquirer-autocomplete-prompt" ;
33import { buildError } from "./error.js" ;
44
5- const prompt = inquirer . createPromptModule ( { output : process . stderr } )
5+ const prompt = inquirer . createPromptModule ( { output : process . stderr } ) ;
66prompt . registerPrompt ( "autocomplete" , autocomplete ) ;
77
8-
98const regions = [
109 "us-east-2" ,
1110 "us-east-1" ,
@@ -33,52 +32,50 @@ const regions = [
3332] ;
3433
3534export const addProfile = ( configstore ) =>
36- prompt ( [
37- {
38- type : "input" ,
39- name : "profileName" ,
40- message : "Name of your SSO profile:" ,
35+ prompt ( [
36+ {
37+ type : "input" ,
38+ name : "profileName" ,
39+ message : "Name of your SSO profile:" ,
40+ } ,
41+ {
42+ type : "autocomplete" ,
43+ name : "region" ,
44+ message : "Select the region where your AWS SSO service is running." ,
45+ source : ( result , input ) => {
46+ return regions . filter ( ( str ) => str . includes ( input || "" ) ) ;
4147 } ,
42- {
43- type : "autocomplete" ,
44- name : "region " ,
45- message : "Select the region where your AWS SSO service is running. " ,
46- source : ( result , input ) => {
47- return regions . filter ( ( str ) => str . includes ( input || "" ) ) ;
48- } ,
48+ } ,
49+ {
50+ type : "input " ,
51+ name : "startUrl " ,
52+ message : "Your SSO start URL (e.g. https://<your-alias>.awsapps.com/start):" ,
53+ validate : ( value ) => {
54+ return value . match ( / ^ h t t p s ? : \/ \/ \w + \. a w s a p p s . c o m \/ s t a r t $ / g ) ? true : "Invalid start URL." ;
4955 } ,
50- {
51- type : "input" ,
52- name : "startUrl" ,
53- message : "Your SSO start URL (e.g. https://<your-alias>.awsapps.com/start):" ,
54- validate : ( value ) => {
55- return value . match ( / ^ h t t p s ? : \/ \/ \w + \. a w s a p p s .c o m \/ s t a r t $ / g) ? true : "Invalid start URL." ;
56- } ,
56+ } ,
57+ ] ) . then ( ( { profileName, region, startUrl } ) => {
58+ configstore . set ( {
59+ [ profileName ] : {
60+ region : region ,
61+ startUrl : startUrl ,
5762 } ,
58- ] )
59- . then ( ( { profileName, region, startUrl } ) => {
60- configstore . set ( {
61- [ profileName ] : {
62- region : region ,
63- startUrl : startUrl ,
64- } ,
65- } ) ;
6663 } ) ;
64+ } ) ;
6765
6866export const deleteProfile = ( configstore ) =>
69- prompt ( {
70- type : "list" ,
71- name : "profile" ,
72- message : "Select the profile you with to remove." ,
73- choices : Object . keys ( configstore . all ) ,
74- } )
75- . then ( ( { profile } ) => {
76- console . error ( profile ) ;
77- if ( ! ( profile in configstore . all ) ) {
78- throw buildError ( "ERR_INVALID_PROFILE" ) ;
79- }
80- configstore . delete ( profile ) ;
81- } ) ;
67+ prompt ( {
68+ type : "list" ,
69+ name : "profile" ,
70+ message : "Select the profile you with to remove." ,
71+ choices : Object . keys ( configstore . all ) ,
72+ } ) . then ( ( { profile } ) => {
73+ console . error ( profile ) ;
74+ if ( ! ( profile in configstore . all ) ) {
75+ throw buildError ( "ERR_INVALID_PROFILE" ) ;
76+ }
77+ configstore . delete ( profile ) ;
78+ } ) ;
8279
8380export const chooseProfile = async ( configstore ) => {
8481 if ( ! configstore || ! Object . keys ( configstore . all ) . length ) {
0 commit comments