@@ -8,14 +8,15 @@ import (
88 "sort"
99 "strings"
1010
11+ "github.com/manifoldco/promptui"
1112 "github.com/user-cube/aws-cli-manager/v2/pkg/models"
1213 "github.com/user-cube/aws-cli-manager/v2/pkg/settings"
1314 "github.com/user-cube/aws-cli-manager/v2/pkg/sharedModules"
1415 "github.com/user-cube/aws-cli-manager/v2/pkg/ui"
1516 "gopkg.in/yaml.v2"
1617)
1718
18- func SelectProfile () {
19+ func SelectProfile () bool {
1920 // Get current profile first
2021 currentProfile := GetCurrentProfile ()
2122 profileNames , awsProfiles := GetProfiles ()
@@ -52,13 +53,20 @@ func SelectProfile() {
5253
5354 index , _ , err := prompt .Run ()
5455 if err != nil {
56+ // Check if it's an interrupt error (Ctrl+C)
57+ if err == promptui .ErrInterrupt {
58+ fmt .Println ("\n Profile selection cancelled" )
59+ return false
60+ }
61+ // Handle other errors
5562 ui .PrintError ("Error selecting profile: %v" , err )
5663 os .Exit (1 )
5764 }
5865
5966 // Get the selected profile name
6067 selectedProfile := sortedNames [index ]
6168 setProfile (selectedProfile , awsProfiles )
69+ return true
6270}
6371
6472func GetProfiles () (profileNames []string , awsProfiles models.AwsProfile ) {
@@ -203,6 +211,12 @@ func PromptProfileName() string {
203211
204212 result , err := prompt .Run ()
205213 if err != nil {
214+ // Check if it's an interrupt error (Ctrl+C)
215+ if err == promptui .ErrInterrupt {
216+ fmt .Println ("\n Profile creation cancelled" )
217+ os .Exit (0 )
218+ }
219+ // Handle other errors
206220 ui .PrintError ("Failed to get profile name: %v" , err )
207221 os .Exit (1 )
208222 }
@@ -231,6 +245,11 @@ func PromptProfileDetails() models.ProfileDetails {
231245
232246 region , err := regionPrompt .Run ()
233247 if err != nil {
248+ // Check if it's an interrupt error (Ctrl+C)
249+ if err == promptui .ErrInterrupt {
250+ fmt .Println ("\n Profile creation cancelled" )
251+ os .Exit (0 )
252+ }
234253 ui .PrintError ("Failed to get region: %v" , err )
235254 os .Exit (1 )
236255 }
@@ -244,6 +263,11 @@ func PromptProfileDetails() models.ProfileDetails {
244263
245264 ssoIndex , _ , err := ssoPrompt .Run ()
246265 if err != nil {
266+ // Check if it's an interrupt error (Ctrl+C)
267+ if err == promptui .ErrInterrupt {
268+ fmt .Println ("\n Profile creation cancelled" )
269+ os .Exit (0 )
270+ }
247271 ui .PrintError ("Failed to get SSO information: %v" , err )
248272 os .Exit (1 )
249273 }
@@ -257,6 +281,11 @@ func PromptProfileDetails() models.ProfileDetails {
257281
258282 config , err := configPrompt .Run ()
259283 if err != nil {
284+ // Check if it's an interrupt error (Ctrl+C)
285+ if err == promptui .ErrInterrupt {
286+ fmt .Println ("\n Profile creation cancelled" )
287+ os .Exit (0 )
288+ }
260289 ui .PrintError ("Failed to get config file information: %v" , err )
261290 os .Exit (1 )
262291 }
@@ -275,6 +304,11 @@ func PromptProfileDetails() models.ProfileDetails {
275304
276305 credentials , err := credentialsPrompt .Run ()
277306 if err != nil {
307+ // Check if it's an interrupt error (Ctrl+C)
308+ if err == promptui .ErrInterrupt {
309+ fmt .Println ("\n Profile creation cancelled" )
310+ os .Exit (0 )
311+ }
278312 ui .PrintError ("Failed to get credentials file information: %v" , err )
279313 os .Exit (1 )
280314 }
0 commit comments