@@ -8,14 +8,15 @@ import (
8
8
"sort"
9
9
"strings"
10
10
11
+ "github.com/manifoldco/promptui"
11
12
"github.com/user-cube/aws-cli-manager/v2/pkg/models"
12
13
"github.com/user-cube/aws-cli-manager/v2/pkg/settings"
13
14
"github.com/user-cube/aws-cli-manager/v2/pkg/sharedModules"
14
15
"github.com/user-cube/aws-cli-manager/v2/pkg/ui"
15
16
"gopkg.in/yaml.v2"
16
17
)
17
18
18
- func SelectProfile () {
19
+ func SelectProfile () bool {
19
20
// Get current profile first
20
21
currentProfile := GetCurrentProfile ()
21
22
profileNames , awsProfiles := GetProfiles ()
@@ -52,13 +53,20 @@ func SelectProfile() {
52
53
53
54
index , _ , err := prompt .Run ()
54
55
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
55
62
ui .PrintError ("Error selecting profile: %v" , err )
56
63
os .Exit (1 )
57
64
}
58
65
59
66
// Get the selected profile name
60
67
selectedProfile := sortedNames [index ]
61
68
setProfile (selectedProfile , awsProfiles )
69
+ return true
62
70
}
63
71
64
72
func GetProfiles () (profileNames []string , awsProfiles models.AwsProfile ) {
@@ -203,6 +211,12 @@ func PromptProfileName() string {
203
211
204
212
result , err := prompt .Run ()
205
213
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
206
220
ui .PrintError ("Failed to get profile name: %v" , err )
207
221
os .Exit (1 )
208
222
}
@@ -231,6 +245,11 @@ func PromptProfileDetails() models.ProfileDetails {
231
245
232
246
region , err := regionPrompt .Run ()
233
247
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
+ }
234
253
ui .PrintError ("Failed to get region: %v" , err )
235
254
os .Exit (1 )
236
255
}
@@ -244,6 +263,11 @@ func PromptProfileDetails() models.ProfileDetails {
244
263
245
264
ssoIndex , _ , err := ssoPrompt .Run ()
246
265
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
+ }
247
271
ui .PrintError ("Failed to get SSO information: %v" , err )
248
272
os .Exit (1 )
249
273
}
@@ -257,6 +281,11 @@ func PromptProfileDetails() models.ProfileDetails {
257
281
258
282
config , err := configPrompt .Run ()
259
283
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
+ }
260
289
ui .PrintError ("Failed to get config file information: %v" , err )
261
290
os .Exit (1 )
262
291
}
@@ -275,6 +304,11 @@ func PromptProfileDetails() models.ProfileDetails {
275
304
276
305
credentials , err := credentialsPrompt .Run ()
277
306
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
+ }
278
312
ui .PrintError ("Failed to get credentials file information: %v" , err )
279
313
os .Exit (1 )
280
314
}
0 commit comments